Read Before Written
static struct worker *g_worker; /* starts NULL */
void init(void) { /* thread 1 */
g_worker = worker_create(worker_main, NULL);
}
void worker_main(void *unused) { /* thread 2, started inside worker_create */
int state = g_worker->state; /* crashes here */
...
}
The new thread occasionally dereferences NULL on its very first line. Which fix is correct?
Sign in to answer questions and track your progress
Sign In