Eugene Zolenko wrote:
>...
> Actually this code still has problems with multithreading. Following
> operation must be atomic: (if s_objectState == 0 then s_objectState =
> 1), and there is no way to guarantee that. 2 threads can enter segment
> [1]-[2] if one loses execution time between "switch (s_objectState)"
> and [1]. I'm not sure it is possible to make this thread-safe without
> actual lock. (might be possible in C++0x with new atomic<>  stuff, but
> not yet)

This is just the classic atomic "test-and-set" operation, which may not 
have a platform-independent expression... but on Win32 could be done with

InterlockedBitTestAndSet(...)

or possibly the more general

InterlockedCompareExchange(...).

In some cases, these are compiled as compiler "intrinsics" - avoiding 
runtime OS/scheduler interaction.

Other platforms typically have their own ways of performing these types 
of operations.

Of course, if you want it all done in the language... ;)

Robert Roessler
[email protected]
http://www.rftp.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to