qemu-iotests: support per-format golden output files
[qemu/ar7.git] / tests / tcg / testthread.c
blob810ba5de67b3b1c762112517aa3697ee69b56ff9
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <inttypes.h>
7 #include <pthread.h>
8 #include <sys/wait.h>
9 #include <sched.h>
11 void checked_write(int fd, const void *buf, size_t count)
13 ssize_t rc = write(fd, buf, count);
14 assert(rc == count);
17 void *thread1_func(void *arg)
19 int i;
20 char buf[512];
22 for(i=0;i<10;i++) {
23 snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg);
24 checked_write(1, buf, strlen(buf));
25 usleep(100 * 1000);
27 return NULL;
30 void *thread2_func(void *arg)
32 int i;
33 char buf[512];
34 for(i=0;i<20;i++) {
35 snprintf(buf, sizeof(buf), "thread2: %d %s\n", i, (char *)arg);
36 checked_write(1, buf, strlen(buf));
37 usleep(150 * 1000);
39 return NULL;
42 void test_pthread(void)
44 pthread_t tid1, tid2;
46 pthread_create(&tid1, NULL, thread1_func, "hello1");
47 pthread_create(&tid2, NULL, thread2_func, "hello2");
48 pthread_join(tid1, NULL);
49 pthread_join(tid2, NULL);
50 printf("End of pthread test.\n");
53 int main(int argc, char **argv)
55 test_pthread();
56 return 0;