aboutsummaryrefslogtreecommitdiff
path: root/test cases/common/98 threads/threadprog.c
blob: 5db40f1afcebbe912371e75c280909ac675353a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#if defined _WIN32

#include<windows.h>
#include<stdio.h>

DWORD WINAPI thread_func() {
    printf("Printing from a thread.\n");
    return 0;
}

int main() {
    DWORD id;
    HANDLE th;
    printf("Starting thread.\n");
    th = CreateThread(NULL, 0, thread_func, NULL, 0, &id);
    WaitForSingleObject(th, INFINITE);
    printf("Stopped thread.\n");
    return 0;
}
#else

#include<pthread.h>
#include<stdio.h>

void* main_func() {
    printf("Printing from a thread.\n");
    return NULL;
}

int main() {
    pthread_t thread;
    int rc;
    printf("Starting thread.\n");
    rc = pthread_create(&thread, NULL, main_func, NULL);
    rc = pthread_join(thread, NULL);
    printf("Stopped thread.\n");
    return rc;
}

#endif