-
March 27th, 2009, 04:10 AM
#1
consequences of race condition
Hello everyone, I'm new here and would like your thoughts on the following 'code' snippet with two followup questions
static int x=0;
int main()
{
new thread1();
while 1
{
inc();
}
}
void thread1
{
while 1
{
inc();
}
}
void inc()
{
if (++x%100 ==0)
{
printf("another +/- 100 ops x=%d", x);
}
sleep(0);
}
Am I right to expect that both threads may (from time to time) print the message for the same 100 operations?
If the above is true, then perhaps x might be 500 when there have been 502 operations performed?
The reason I am asking is because if the above are the only two consequences of the race condition then in this case, it's acceptable.
Many Thanks.
Tags for this Thread
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
|