|
-
November 20th, 2008, 12:49 PM
#1
working with locks/critical sections
I have done a bit of multithreading before, but it has never been a situation until now where i have needed to actually synchronize the threads. As I have very little experience working with thread sync I had a few questions.
I have read the msdn pages on the win32 critical section functions, and basically understand how to use them. before i started using the win32 functions though, i had tried this:
Code:
#define LFS_LOCKED !!( logfstream::properties & LFSTREAM_LOCKED )
#define ENTER_LFS_LOCK_ while( LFS_LOCKED ){ } properties |= LFSTREAM_LOCKED;
#define EXIT_LFS_LOCK_ properties &= ~LFSTREAM_LOCKED;
where 'properties' is just a static int.
essentially, i realize now, that it is similar to a critical section with infinite spin count. although i had no problems when using the above code, my question is... what problems could there be using it, or is it viable code to use for thread sync?
ps - if i wrote some kind of wrapper for this that would sleep/activate threads and act as a true thread sync object, would that be ok, or is this something that the operating system HAS to handle to truly prevent any thread problems (i.e. don't bother trying, just use win32)?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|