On 05/30/2012 03:39 AM, Roger Oberholtzer wrote:
I have a threaded application that encounters a segmentation violation. I am fairly certain it is the initial thread that encounters the problem. But I just want to be sure of the following:
1. If a multi-threaded app encounters a seg violation, and a core dump is created, the core is of the thread that encountered the seg violation, and not of the main thread, right?
2. If a process starts a thread, and that thread exits, the process does not know about this until it tries to join the thread, right? So, if a thread has a seg violation and exits, the 'parent' thread will also not be made exit. It has to detect the thread is gone by it's own mechanisms or by trying to join the thread. I ask this because I want to be certain I am not misinterpreting which thread in my application is the one that really is getting the seg violation.
This is on openSUSE 11.2 with kernel 2.6.31.14-51-desktop
" If a process starts a thread, and that thread exits, the process does not know about this until it tries to join the thread, right?" Not entirely true. There are a number of ways to allow a thread to exit avoiding the need to join. It has been a few years since I was working with pthreads, but you can set up a thread as detached. The main issue you need to understand is that unlike processes, threads run in the context of the thread creator. So, a segv in a thread will cause the entire process to fail. One of the things that really helps in thread programming is exception processing and try blocks. By wrapping sections of your code in try blocks you can avoid this nastiness. Additionally, if you have multiple child threads. Additionally I always recommend my former coworker, Dave Butenhof's books. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix PGP key id:3BC1EB90 PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66 C0AF 7CEA 30FC 3BC1 EB90