Witam..
Mam nastepujacy problem - jak zakonczyc watek?
mam nastepujacy kod:
#include <stdio.h>
#include <pthread.h>
void * threadfn(void *arg) {
while(1) {
sleep(2);
printf("\n %s", (char *) arg);
}
}
int main(void) {
pthread_t th1, th2;
pthread_create(&th1, NULL, threadfn, "watek 1..");
pthread_create(&th2, NULL, threadfn, "watek 2..");
sleep(10);
pthread_kill(th1, 9);
sleep(10);
pthread_kill(th2, 9);
return 0;
}
Po odpaleniu:
./threads-test
watek 1..
watek 2..
watek 1..
watek 2..
watek 1..
watek 2..
watek 1..
Unicestwiony
Pytanie - dlaczego ubija mi caly proces a nie jeden watek?
Probowalem tez inaczej, korzystajac z pthread_join.. wtedy jednak watek 1 sie nie konczy..
Bylbym wdzieczny za wyjasnienie jak to obsluzyc, ew. jakis solidny link do materialow o pthread.
Btw. GCC 3.3.3, Linux
Pozdrawiam
Maciek