in Education by
I'm wondering, and in need, of strategies that can be applied to reducing low-level locking. However the catch here is that this is not new code (with tens of thousands of lines of C++ code) for a server application, so I can't just rewrite the whole thing. I fear there might not be a solution to this problem by now (too late). However I'd like to hear about good patterns others have used. Right now there are too many lock and not as many conflicts, so it's a paranoia induced hardware performance issue. The best way to describe the code is as single threaded code suddenly getting peppered with locks. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Why do you need to eliminate the low-level locking? Do you have deadlock issues? Do you have performance problems? Or scaling issues? Are the locks generally contended or uncontended? What environment are you using? The answers in C++ will be different to the ones in Java, for example. E.g. uncontended synchronization blocks in Java 6 are actually relatively cheap in performance terms, so simply upgrading your JRE might get you past whatever problem you are trying to solve. There might be similar performance boosts available in C++ by switching to a different compiler or locking library. In general, there are several strategies that allow you to reduce the number of mutexes you acquire. First, anything only ever accessed from a single thread doesn't need a mutex. Second, anything immutable is safe provided it is 'safely published' (i.e. created in such a way that a partially constructed object is never visible to another thread). Third, most platforms now support atomic writes - which can help when a single primitive type (including a pointer) is all that needs protecting. These work very similarly to optimistic locking in a database. You can also use atomic writes to create lock-free algorithms to replace more complex types, including Map implementations. However, unless you are very, very good, you are much better off borrowing somebody else's debugged implementation (the java.util.concurrent package contains lots of good examples) - it is notoriously easy to accidentally introduce bugs when writing your own algorithms. Fourth, widening the scope of the mutex can help - either simply holding open a mutex for longer, rather than constantly locking and unlocking it, or taking a lock on a 'larger' item - the object rather than one of its properties, for example. However, this has to be done extremely carefully; you can easily introduce problems this way.

Related questions

0 votes
    If a node is locked in ____________ then explicit locking is being done at a lower level, with exclusive- ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    If a node is locked in __________ explicit locking is being done at a lower level of the tree, but ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    If a node is locked in an intention mode, explicit locking is done at a lower level of the tree. ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    If a node is locked in ______________ the subtree rooted by that node is locked explicitly in shared ... Granularity topic in division Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    How to delete unpublished Git commits and get rid of them permanently? A. git reset –hard B. git revert C. git reset –soft...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    The Cookies Preferences box that always appears in the bottom right hand corner of the dataplatform.ibm.com ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    When I'm making a request to my backend through a mutation like that: mutation{ resetPasswordByToken(token:" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    This one has been bugging me for a while now. Is there a way I can stop Intellj IDEA from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Select * from OPENQUERY (PORTAL, ''SELECT st.last AS "Last Name", st.first AS "First Name", ct. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    is there an easy way to not draw this points in my lines? I don't know why this points are ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    How to get rid of Date Filter in Salesforce?...
asked Nov 12, 2020 in Technology by JackTerrance
0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    Q.20 Low-level language which is written in Octal O English Hexadecimal Binary Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Java in computer programming is a- (a) Compiler (b) Hardware Device Driver (c) Low-level Language (d ... Programming Mid-level Language Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Multiple Choice Questions 1. Visual Basic is a (a) low-level programming language. (b) medium-level (c) high- ... files of a project. Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
...