Does C++ provide synchronize method?
Does C++ provide synchronized method like that:
[Java]
class Test{
synchronized void Something(){.....}
}
If yes, how to do that?
Thanks
No, you need to manually use some synchronization method (events, mutexes, semaphores)
Forever trusting who we are
And nothing else matters - Metallica
Forever trusting who we are
And nothing else matters - Metallica
No, it doesn''t, and it doesn''t really need them, either, because it has no notion of threads.
Which in turn means that if you find yourself some thread implementation, that will have its own facilities for enforcing synchronisation. (Which admittedly won''t be as clean as Java''s, but is potentially more flexible.)
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions ]
Mm.....I have two threads. Those are GameController and NetworkController. Also, i have a SharedMemory Handler.
The GameController handles the game flow. e.g. hero move in map...
NetworkController handles the send and receive data from/to server....
The SharedMemory Handler is a common area that store all other online player''s heros data those are in the same map...
I want to make one and only one controller can access the SharedMemory''s data at a time. So i remember java provided synchronized method for me to do that. How can i do that at C++?
The GameController handles the game flow. e.g. hero move in map...
NetworkController handles the send and receive data from/to server....
The SharedMemory Handler is a common area that store all other online player''s heros data those are in the same map...
I want to make one and only one controller can access the SharedMemory''s data at a time. So i remember java provided synchronized method for me to do that. How can i do that at C++?
Threads are not functions of C/C++--they're only available through libraries, usually interfacing the OS. How are you starting your thread? If you tell us what library you're using for threads, we can probably tell you what synchronization primitives the library offers.
For example, if you're using win32, you've got InitializeCriticalSection, CreateMutex, CreateSemaphore, etc.
[edited by - Stoffel on April 17, 2002 1:09:34 PM]
For example, if you're using win32, you've got InitializeCriticalSection, CreateMutex, CreateSemaphore, etc.
[edited by - Stoffel on April 17, 2002 1:09:34 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement