??????????????????????????????????Linux???????????????????????????????????????????????????????????С????????????????????Linux????????3?桷??
????1.Linux?????????
????Linux??????????????????????????????????????????????????????????????????????????????????????д??????????????????????????
????Linux???fork??????????????????????в????fork???????y??????????????????????????????????????PID???????????????????????????в?????????????????
????????????????????????????λ?????????????????????λ???????????????????乲??????????????
????2._REENTRANT??
??????????????????????????£??????????errno?????????????????????????????????????????????????????easy?????????????е????????????????????????????fputs????????У???Щ????????????????????????????????????????????
?????????????????????????????????????????????ε???????????????????д?????????????????_REENTRANT????????????????????????????????????????????????е??????#include???????
????_REENTRANT??????????????飬??????????????
??????1?????????????????ζ????????????????汾?????Щ???????????????????????????????????????_r????????純????gethostbyname???gethostbyname_r??
??????2??stdio.h?????????????????Щ????????????????????
??????3????error.h?ж???????error??????????????????????????????????????????????????errno?????
????3.???????????
?????????pthread_XXX??е??????????????δ???UNIX?????????????-1?????????????UNIX???????????????????????ó???????????0???????????????????
????1??.????????
????#include <pthread.h>
????int pthread_create(pthread_t *thread?? pthread_attr_t *attr?? void *(*start_routine)(void *)?? void *arg);
????????????
????thread?????pthread_create?????????????????′?????????
????attr???????????????????????????????????????????????????NULL??
????*(*start_routine)(void *)?????????????????е?????????
????arg?????????????е???????????
???????ü??????????????0???????????????????
????2??.??????
????#include <pthread.h>
????void pthread_exit(void *retval);
????????????
????retval??????????????????????????????
??????????????pthread_exit??????????У??????????????????????????????????????????????????????????????????ú???????????????????????????????????????????
????3??.??????
????#include <pthread.h>
????int pthread_join(pthread_t th?? void **thread_return);
????????????
????th????????????責???????pthread_create????????????????
????thread_return??????????????????????????????????????
???????????????Demo??thread1.c????
??????????????????????????_REENTRANT??
????gcc -D_REENTRANT thread1.c -o thread1 –lpthread
??????????????
????$ ./thread1?????
????thread_function is running. Argument was Hello World
????Waiting for thread to finish...
????Thread joined?? it returned Thank you for your CPU time!
????Message is now Bye!
?????????????????????????????????????????????????????
????pthread_exit(void *retval)????????????????????????????pthread_join(pthread_t th?? void **thread_return);?е?thread_return???????????????????????
???????????????????????????????????message?????????????????????????顣??????????????fork??????pthread_create????????????Ч??????????fork??????????????????????????????????????????????????????????????????????