File:  [Qemu by Fabrice Bellard] / qemu / tests / testthread.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:37:52 2018 UTC (3 years, 3 months ago) by root
Branches: qemu, MAIN
CVS tags: qemu1001, qemu1000, qemu0151, qemu0150, qemu0141, qemu0140, qemu0130, qemu0125, qemu0124, qemu0123, qemu0122, qemu0121, qemu0120, qemu0111, qemu0110, qemu0105, qemu0104, qemu0103, qemu0102, qemu0101, qemu0100, qemu0091, qemu0090, qemu0082, qemu0081, qemu0080, qemu0072, HEAD
qemu 0.7.2

    1: #include <stdlib.h>
    2: #include <stdio.h>
    3: #include <string.h>
    4: #include <signal.h>
    5: #include <unistd.h>
    6: #include <inttypes.h>
    7: #include <pthread.h>
    8: #include <sys/wait.h>
    9: #include <sched.h>
   10: 
   11: void *thread1_func(void *arg)
   12: {
   13:     int i;
   14:     char buf[512];
   15: 
   16:     for(i=0;i<10;i++) {
   17:         snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg);
   18:         write(1, buf, strlen(buf));
   19:         usleep(100 * 1000);
   20:     }
   21:     return NULL;
   22: }
   23: 
   24: void *thread2_func(void *arg)
   25: {
   26:     int i;
   27:     char buf[512];
   28:     for(i=0;i<20;i++) {
   29:         snprintf(buf, sizeof(buf), "thread2: %d %s\n", i, (char *)arg);
   30:         write(1, buf, strlen(buf));
   31:         usleep(150 * 1000);
   32:     }
   33:     return NULL;
   34: }
   35: 
   36: void test_pthread(void)
   37: {
   38:     pthread_t tid1, tid2;
   39: 
   40:     pthread_create(&tid1, NULL, thread1_func, "hello1");
   41:     pthread_create(&tid2, NULL, thread2_func, "hello2");
   42:     pthread_join(tid1, NULL);
   43:     pthread_join(tid2, NULL);
   44:     printf("End of pthread test.\n");
   45: }
   46: 
   47: int main(int argc, char **argv)
   48: {
   49:     test_pthread();
   50:     return 0;
   51: }

unix.superglobalmegacorp.com