Given the following scenario:
- 2 Threads (no more, no less)
- A shared variable (let's say a void *)
- One thread writes to the variable ONLY once (this is guaranteed)
- And the other thread is responsible for reading the variable
Is it thread safe to have the reader thread check for null of the variable? Explicitly in a C program?
Example code:
Thread 1:
void initOnStartup()
{
ptr = malloc(10);
}
Thread 2:
void waitingForValue()
{
while(!ptr);
}