Hi,
Is there a standard / highly efficient way to acquire a resource in
exclusive fashion, if we already hold it in shared way, without allowing
any other thread to acquire it in exclusive way before us? (semantically
this would be somehow the inverse of ExConvertExclusiveToSharedLite)
The scenario where I would need this is the following: I have a quite
huge list of objects, protected by a resource. I typically only need to
get a reference to one of those objects, if it is already in the list. For
this, I acquire the resource in a shared fashion. Now, in certain
situations,
when I walk through the list and do NOT found the particular object I’m
looking for, I need to allocate a new object and insert it into the list.
Now, for this I need exclusive access. But, if I already have shared access,
then I must previously release the shared resource. After this, if I get the
exclusive access I can’t be sure, that some other thread meanwhile didn’t
already inserted that object into the thread (in a highly concurrent way).
What I want to avoid is the re-verification of the list (looking for the
object) after I get the exclusive access.
any suggestions how to solve this?
thank you, have a nice day,
Sandor LUKACS
Virus Analyst, SOFTWIN