|
I'm still confused... When we write some thing like this:
Object o = new Object(); var resource = new Dictionary<int , SomeclassReference>();
...and have two blocks of code that lock o while accessing resource ...
//Code one lock(o) { // read from...
Started by SilverHorse on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
You can lock on any object, you may want use a....
Yes, using a lock is the right way to go.
Be a singleton or scoped across everywhere that lock is needed, as what is REALLY being locked is that object, it will have to wait.
|
|
Possible Duplicates:
Why is lock(this) {...} bad?
In C# it is common to use lock(objLock) where objLock is an object created simply for the purpose of locking.
Why is this preferable to lock(this)? What are the negative implications of lock(this) other...
Started by miguel on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If you lock anything public, then both the class and some other class can try to get a lock....
If you lock else is going to lock on it unexpectedly.
Because something else could lock the instance, then you'd have a deadlock.
|
|
Which is preferred boost::lock_guard or boost::mutex::scoped_lock ?
I'm using Boost.Thread with the hope to move to C++0x threading when it becomes available.
Is scoped_lock part of the next c++ standard?
Are the any advantages to prefer one over the ...
Started by Caspin on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The difference between is simply that unique_lock....
Both of unique_lock and lock_guard implement RAII-style locking.
As per Boost , scoped_lock is a typedef for unique_lock<mutex> .
Not much difference between the two.
|
Ask your Facebook Friends
|
Hi Guys,
It is mentioned that one of the advantages of Lock (java.util.concurrent.locks.Lock) over intrinsic lock is that Lock facilitates "chain locking". Chain locking being, hold a lock for A, then acquire B, after acquiring B release A and then acquire...
Started by CaptainHastings on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
A lock chain could be used to enforce....
Not ideal if you have long complicated pipelines.
One resource before you have acquired the next in the sequence, a lock chain is a convenient solution release a lock in the order you acquired it.
|
|
In a c# threading app, if I were to lock an object, let us say a queue, and if an exception occurs, will the object stay locked? Here is the pseudo-code:
int ii; lock(MyQueue) { MyClass LclClass = (MyClass)MyQueue.Dequeue(); try { ii = int.parse(LclClass...
Started by Khadaji on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
} finally { Monitor.Exit(lockObj); }
Second; you catch and don't re-throw the ... .
Is now assigned } else { // input string is dodgy }
The lock will be released for 2 reasons; first, lock is essentially:
Monitor.Enter(lockObj); try { // ...
|
|
I am working on a piece of code which uses regular expressions in c.
All of the regex stuff is using the standard regex c library.
On line 246 of regexec.c, the line is
__libc_lock_lock(dfa->lock);
My program is segfaulting here and I cannot figure...
Started by Matt on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
*/ 68:#define __libc_lock_lock(NAME) __mutex_lock (&(NAME)).
Glibc release is 2.2.5
67:/* Lock the named lock variable.
|
|
I'm having thread contention in an OLTP app. While reviewing the code involved, I found the following:
lock (_pendingTransactions) { transaction.EndPointRequest.Request.Key = (string)MessageComparer.GenerateKey(transaction.EndPointRequest.Request); if...
Started by Federico González on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
A dedicated lock field is of type ....
Generally speaking, one will take a lock on an object specifically because one is going to modify discouraged, with the recommendation being to use a dedicated lock field (class member variable).
|
|
In Vista, I had previously made my caps lock function as a control key, the problem is I don't know how to undo the change. I have searched around and most references I find mention changing the ScancodeMap in the registry but this isn't working for me...
Started by Matt Haley on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at superuser):
If your caps lock and control key are swapped with something other than.
SharpKeys should allow you to fix that, just map Caps Lock back to itself:
There is also that came with the keyboard.
|
|
Every keyboard I have ever seen contained a caps lock and scroll lock key. However, I have never figured out what scroll lock is for, and the caps lock key has always annoyed me (I have disabled it using AutoHotkey :-). I wonder what both keys are good...
Started by Dimitri C. on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at superuser):
When ....
In the original design, scroll lock was intended to modify the behavior of the arrow keys.
Here's what it says on Wikipedia about the scroll lock key:
The scroll lock key was meant to lock by most modern-day software.
|
|
I have found possible slowdown in my app so I would have two questions:
What is the real difference between simple locking on object and reader/writer locks? E.g. I have a collection of clients, that change quickly. For iterations should I use readerlock...
Started by Tomas on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
A reader lock for the whole duration of your iterator:
Obtain reader lock Iterate over collection Release reader lock Note this is not the same as obtaining a reader lock for each step of the iteration of a reader/writer ....
|