cpu-exec: simplify align_clocks
[qemu.git] / tests / tcg / testthread.c
blob2679af119ac23669415cc0a4fb1460208a6bc61d
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <signal.h>
6 #include <unistd.h>
7 #include <inttypes.h>
8 #include <pthread.h>
9 #include <sys/wait.h>
10 #include <sched.h>
12 void checked_write(int fd, const void *buf, size_t count)
14 ssize_t rc = write(fd, buf, count);
15 assert(rc == count);
18 void *thread1_func(void *arg)
20 int i;
21 char buf[512];
23 for(i=0;i<10;i++) {
24 snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg);
25 checked_write(1, buf, strlen(buf));
26 usleep(100 * 1000);
28 return NULL;
31 void *thread2_func(void *arg)
33 int i;
34 char buf[512];
35 for(i=0;i<20;i++) {
36 snprintf(buf, sizeof(buf), "thread2: %d %s\n", i, (char *)arg);
37 checked_write(1, buf, strlen(buf));
38 usleep(150 * 1000);
40 return NULL;
43 void test_pthread(void)
45 pthread_t tid1, tid2;
47 pthread_create(&tid1, NULL, thread1_func, "hello1");
48 pthread_create(&tid2, NULL, thread2_func, "hello2");
49 pthread_join(tid1, NULL);
50 pthread_join(tid2, NULL);
51 printf("End of pthread test.\n");
54 int main(int argc, char **argv)
56 test_pthread();
57 return 0;