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 static void *thread1_func(void *arg)
00025 {
00026 int i;
00027
00028 printf("thread has started\n");
00029 for (i = 0; ; i++) {
00030 sleep(1);
00031 printf("%d\n", i);
00032 }
00033 }
00034
00035 int main(void)
00036 {
00037 pthread_t tid;
00038 char s[10];
00039 void *exit_val;
00040
00041 printf("main program has started\n");
00042
00043 ec_rv( pthread_create(&tid, NULL, thread1_func, NULL) )
00044 (void)fgets(s, sizeof(s), stdin);
00045 printf("cancelling thread\n");
00046 ec_rv( pthread_cancel(tid) )
00047 ec_rv( pthread_join(tid, &exit_val) )
00048 if (exit_val == PTHREAD_CANCELED)
00049 printf("thread was cancelled\n");
00050 return EXIT_SUCCESS;
00051
00052 EC_CLEANUP_BGN
00053 return EXIT_FAILURE;
00054 EC_CLEANUP_END
00055 }