1
/* This is a test program for KDevelop GDB debugger support.
3
There are two worker threads, they are programmed to call
4
the 'foo' function in strictly interleaved fashion.
11
int schedule[] = {1, 2};
12
int schedule_size = sizeof(schedule)/sizeof(schedule[0]);
16
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
17
pthread_cond_t condition = PTHREAD_COND_INITIALIZER;
19
void foo(int thread, int i)
21
printf ("hi there, from thread %d on iteration %d\n", thread, i);
26
for(int i = 0; i < 1000000 && !exit; ++i)
28
pthread_mutex_lock(&mutex);
30
while (schedule[index] != id) {
31
pthread_cond_wait(&condition, &mutex);
37
if (index >= schedule_size)
40
pthread_cond_broadcast(&condition);
41
pthread_mutex_unlock(&mutex);
57
pthread_create(&p1, 0, &thread, (void*)1);
58
pthread_create(&p2, 0, &thread, (void*)2);