btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / tests / system / kernel / sem_acquire_test1.cpp
blob8652cc986dc956f54768d57551c1f3fe4f2707ac
1 #include <stdio.h>
2 #include <string.h>
4 #include <OS.h>
7 static sem_id sSemaphore = -1;
10 static status_t
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));
17 return error;
21 static status_t
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));
27 return error;
32 int
33 main()
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);
41 snooze(100000);
43 thread_id thread2 = spawn_thread(&thread_function2, "thread2",
44 B_NORMAL_PRIORITY, NULL);
45 resume_thread(thread2);
47 snooze(100000);
49 thread_id thread3 = spawn_thread(&thread_function1, "thread3",
50 B_NORMAL_PRIORITY, (void*)"thread3");
51 resume_thread(thread3);
53 snooze(100000);
55 int32 semCount = 42;
56 get_sem_count(sSemaphore, &semCount);
57 printf("sem count: %ld\n", semCount);
59 printf("killing thread1...\n");
60 kill_thread(thread1);
62 snooze(2000000);
64 return 0;