use volatile variables

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-03-07 10:47:04 +00:00
parent 56c7a5fd3a
commit 695c2d279c

View file

@ -11,10 +11,13 @@
# define mySleep(X) sleep(X)
#endif
static unsigned initialize_entered = 0;
static unsigned initialize_exited = 0;
static unsigned class_entered = 0;
static BOOL may_proceed = NO;
/* Use volatile variables so compiler optimisation won't prevent one thread
* from seeing changes made by another.
*/
static volatile unsigned initialize_entered = 0;
static volatile unsigned initialize_exited = 0;
static volatile unsigned class_entered = 0;
static volatile BOOL may_proceed = NO;
@interface MyClass : NSObject
@end
@ -25,7 +28,7 @@ static BOOL may_proceed = NO;
{
initialize_entered++;
while (NO == may_proceed)
mySleep(1);
;
initialize_exited++;
}