I’ve got a problem in porting a multi-thread-c-programm from Win32 to Linux. On both OS there are very similar functions to create threads.
I use _beginthread in Win32 (process.h) and pthread_create in Linux (pthread.h).
Normaly both functions work fine in both OS – except for one thing: I have to sync the child-thread with the main-program. So both functions/threads get the same pointer to a status variable which tells them whether to wait or to run.
In Win32 this works fine. The same code in Linux produces an endless loop.
The child-thread has something like: while(*status == 0);
“status” is a pointer to an integer.
I know, normally this IS an endless loop. But NOT when the other process changes the value of this variable.
The pointers in both processes point exactly to the same address. In Win32 this loop recognizes when the value has changed. But not in Linux ???!!!
I don’t understand this behaviour at all.
Ahh, I found out something weird:
When the program produces output on the console, the Linux-code works, too.
But I don’t want to produce console-output in this loop!