7 static sem_id sSemaphore
= -1;
11 thread_function1(void* data
)
13 const char* threadName
= (const char*)data
;
14 printf("%s: going to acquire sem...\n", threadName
);
15 status_t error
= acquire_sem_etc(sSemaphore
, 2, 0, 0);
16 printf("%s: acquire_sem_etc() returned: %s\n", threadName
, strerror(error
));
22 thread_function2(void*)
24 printf("thread2: going to acquire sem...\n");
25 status_t error
= acquire_sem_etc(sSemaphore
, 1, 0, 0);
26 printf("thread2: acquire_sem_etc() returned: %s\n", strerror(error
));
35 sSemaphore
= create_sem(1, "test sem");
37 thread_id thread1
= spawn_thread(&thread_function1
, "thread1",
38 B_NORMAL_PRIORITY
, (void*)"thread1");
39 resume_thread(thread1
);
43 thread_id thread2
= spawn_thread(&thread_function2
, "thread2",
44 B_NORMAL_PRIORITY
, NULL
);
45 resume_thread(thread2
);
49 thread_id thread3
= spawn_thread(&thread_function1
, "thread3",
50 B_NORMAL_PRIORITY
, (void*)"thread3");
51 resume_thread(thread3
);
56 get_sem_count(sSemaphore
, &semCount
);
57 printf("sem count: %ld\n", semCount
);
59 printf("killing thread1...\n");