Multi-thread terminated unexpectedly with POSIX threads
Hello,
I am using POSIX threads to create several worker threads and scheduling them to run one by one. However, after some random execution time, all of the worker threads got terminated. In addition, this problem does not happen every time. Could you please kindly suggest how to debug this issue? Thanks very much. Regards, Eric |
Not wanting to sound patronising, but have you tried literally running the code in a debugger? Also, what do you mean by "all of the worker threads got terminated"? Did the whole program terminate? Was there a message printed to the console? What happened?
|
Quote:
|
> But the whole OS crashes
Perhaps your program has eaten up every single bit of memory? |
Quote:
|
You've got a timing hole somewhere. Sux to debug it, but ... :banghead:
|
Quote:
|
Quote:
|
It sounds like your threads are deadlocking. Can you share your code or give a more exacting description of how the threads interact, including all synchronization constructs?
|
Quote:
Regards, Eric |
I read your description again and it actually doesn't sound like deadlock, so sorry about that. sundialsvcs is right that it's likely some race condition in your code...
If there are multiple ways to access an image as it is being processed, then make sure the same mutex lock surrounds the code in each of them. Also, there is a 'try_acquire' or similar in the POSIX threads API. If you are using that, you should consider whether the thread that tries to acquire the lock does something that assumes the lock is held. That said, you should minimize the places where you can access the shared image, probably to synchronous read/write methods and have all access occur through those -- at least to start with. That's all I can think of right now. A debugger probably would help since you'll be able to see what the threads were doing when they crashed. You'll still need to do some reasoning about why what they were doing was allowed to happen. Good luck! |
All times are GMT -5. The time now is 09:33 PM. |