Debian Codegraph @

test cases/common/94 threads/threadprog.c

raw
1 #if defined _WIN32
2
3 #include<windows.h>
4 #include<stdio.h>
5
6 DWORD WINAPI thread_func(void *arg) {
7 printf("Printing from a thread.\n");
8 return 0;
9 }
10
11 int main(void) {
12 DWORD id;
13 HANDLE th;
14 printf("Starting thread.\n");
15 th = CreateThread(NULL, 0, thread_func, NULL, 0, &id);
16 WaitForSingleObject(th, INFINITE);
17 printf("Stopped thread.\n");
18 return 0;
19 }
20 #else
21
22 #include<pthread.h>
23 #include<stdio.h>
24
25 #ifdef HAVE_UNUSED
26 #define UNUSED_ATTR __attribute__((unused))
27 #else
28 #define UNUSED_ATTR
29 #endif
30
31 void* main_func(void UNUSED_ATTR *arg) {
32 printf("Printing from a thread.\n");
33 return NULL;
34 }
35
36 int main(void) {
37 pthread_t thread;
38 int rc;
39 printf("Starting thread.\n");
40 rc = pthread_create(&thread, NULL, main_func, NULL);
41 rc = pthread_join(thread, NULL);
42 printf("Stopped thread.\n");
43 return rc;
44 }
45
46 #endif