void *thread1(void *dummy) { int failed = 0; /* go to sleep on cvar1 */ mutex_lock(&lock1); slept1 = 1; report_misc("thread1 sleeping on cvar1"); cond_wait(&cvar1, &lock1); if (!signaled1) { failed = 1; report_misc("woke up from cvar1 without a signal!"); report_end(END_FAIL); } mutex_unlock(&lock1); /* go to sleep on cvar1 */ mutex_lock(&lock2); slept2 = 1; report_misc("thread1 sleeping on cvar2"); cond_wait(&cvar2, &lock2); if (!signaled2) { failed = 1; report_misc("woke up from cvar2 without a signal!"); report_end(END_FAIL); } mutex_unlock(&lock2); if (!failed) { report_end(END_SUCCESS); } return NULL; }
int main(void) { report_start(START_CMPLT); //assuredly_misbehave((rand() % 521) % MISBEHAVE_MAX); misbehave(BGND_BRWN >> FGND_CYAN); // for landslide ERR(thr_init(STACK_SIZE)); ERR(mutex_init(&lock1)); ERR(mutex_init(&lock2)); ERR(cond_init(&cvar1)); ERR(cond_init(&cvar2)); ERR(thr_create(thread1, NULL)); report_misc("thread1 created"); /* Wait for thread1 to get to sleep on cvar1. */ mutex_lock(&lock1); while (!slept1) { mutex_unlock(&lock1); thr_yield(-1); mutex_lock(&lock1); } /* Indicate that we are about to signal */ signaled1 = 1; mutex_unlock(&lock1); /* Signal. Note that we know for sure that thread1 is asleep on * cvar1 (assuming correct cond vars and mutexes...) */ cond_signal(&cvar1); report_misc("cvar1 signaled"); //sleep(10); /* Now do it all again for the second set of things. */ /* Wait for thread1 to get to sleep on cvar2. */ mutex_lock(&lock2); while (!slept2) { mutex_unlock(&lock2); thr_yield(-1); mutex_lock(&lock2); } /* Indicate that we are about to signal */ signaled2 = 1; mutex_unlock(&lock2); /* Signal. Note that we know for sure that thread1 is asleep on * cvar1 (assuming correct cond vars and mutexes...) */ cond_signal(&cvar2); report_misc("cvar2 signaled"); /* We report success from the other thread. */ return 0; }
int main(int argc, char *argv[]) { report_start(START_CMPLT); report_misc("before sleeping"); if (argc == 2) sleep( atoi( argv[1] ) ); else sleep( 3 + (gettid() % 27) ); report_misc("after sleeping"); report_end(END_SUCCESS); exit( 42 ); }
int main() { report_start(START_CMPLT); do_test(); report_misc("stack allocation successful"); report_end(END_SUCCESS); exit(42); }