About POSIX threads
I am learning about threads in POSIX. I can create a thread that runs a function. But my goal is to have a lot of threads that each has it's own ID-variable that it can use (this is the reason why I chosed threads, it was between threads and forks).
But now the problem is that each thread waits for the other to run. I tried to remove "pthread_join()" but then only one thread ran. Here is the code: Code:
#include <stdio.h> Code:
#100 starting |
The second thread doesn't wait for the first. It's just that thread 1 doesn't exist
long enough to be still there when thread 2 is created. Modify your thread function like this: void *t_func(void *tmp) { int n = (int)tmp; int c=0; printf("#%d starting\n", n); while(c++<10000){ printf(#%d doing something\n"); usleep(1000*50); } printf("#%d ending\n", n); } HTH |
All times are GMT -5. The time now is 01:02 PM. |