I am not creating more than 4 threads at a time.
Actually, you could create unbounded many threads between the call to threads->create() and when that thread finally gets created and runs far enough to execute $tcount++.
You could certainly reduce that potential problem by moving the duplicate threads->create() calls out of the if/else blocks so you have just one copy of it below that and do the $tcount++ there instead of inside of processData(). You could still potentially accumulate unbounded many threads whose execution lies somewhere between the $tcount-- and the actual ending of the thread.
You also don't appear to ever join() nor detach() any of these threads. That surely builds up a growing stash of information about what each thread "returned", much like a memory leak.
These types of problems are part of why the usual pattern is to just create 4 threads and then farm out items to them to execute (usually using a thread queue).
- tye
In reply to Re: Thread creation failed: pthread_create returned 11 (races, leaks)
by tye
in thread Thread creation failed: pthread_create returned 11
by kamrul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |