00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022 #include <pthread.h>
00023
00024
00025 static long x = 0;
00026
00027 static void *thread_func(void *arg)
00028 {
00029 while (x < (long)arg) {
00030 printf("Thread 2 says %ld\n", ++x);
00031 sleep(1);
00032 }
00033 return (void *)x;
00034 }
00035
00036 int main(void)
00037 {
00038 pthread_t tid;
00039 void *status;
00040
00041 assert(sizeof(long) <= sizeof(void *));
00042 ec_rv( pthread_create(&tid, NULL, thread_func, (void *)6) )
00043 while (x < 10) {
00044 printf("Thread 1 says %ld\n", ++x);
00045 sleep(2);
00046 }
00047 ec_rv( pthread_join(tid, &status) )
00048 printf("Thread 2's exit status is %ld\n", (long)status);
00049 return EXIT_SUCCESS;
00050
00051 EC_CLEANUP_BGN
00052 return EXIT_FAILURE;
00053 EC_CLEANUP_END
00054 }
00055