LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-22-2009, 01:42 AM   #1
sky rulz
Member
 
Registered: Jun 2008
Posts: 40

Rep: Reputation: 15
related to multi threaded programming


hi all,

i created a 3 threads and each thread just prints their thread ids.
But when one thread generates a signal (for example SIGFPE) the process terminates because signals are process wide and hence other threads are also terminate.

I want to keep the other threads running and do the job assigned to them. Is there a way to get it done?
 
Old 05-11-2009, 03:33 AM   #2
minge.zu
LQ Newbie
 
Registered: Oct 2008
Location: Beijing
Posts: 17

Rep: Reputation: 0
call the pthread_exit() in your main function after the threads are spawned.
 
Old 05-11-2009, 06:48 AM   #3
kpraveen455
Member
 
Registered: Feb 2009
Location: Hyderabad
Distribution: fedora
Posts: 33

Rep: Reputation: 17
Question

But pthread_exit() will exit the threads, and the question here is to allow the remaining 2 threads to be alive...

Please correct me if i am wrong
 
Old 05-11-2009, 10:34 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
You need to set up a signal handler to capture the incoming signal and process it as you choose.

Though, I must say I am not at all clear on why you would want to use system signals to communicate between threads; there are much better ways.

Last edited by jiml8; 05-11-2009 at 10:40 AM.
 
Old 05-11-2009, 11:44 PM   #5
sky rulz
Member
 
Registered: Jun 2008
Posts: 40

Original Poster
Rep: Reputation: 15
hi praveen

Quote:
Originally Posted by kpraveen455 View Post
But pthread_exit() will exit the threads, and the question here is to allow the remaining 2 threads to be alive...

Please correct me if i am wrong

You got me correct.
i need the other threads to be alive. That is i need the signal to be delivered to the thread that was cause for it and not to the main thread. This makes the other threads alive.
 
Old 05-12-2009, 12:34 AM   #6
sky rulz
Member
 
Registered: Jun 2008
Posts: 40

Original Poster
Rep: Reputation: 15
i used the pthread_exit()

Quote:
Originally Posted by minge.zu View Post
call the pthread_exit() in your main function after the threads are spawned.

hi,
i did use the pthread_exit() after the threads are being spawned. But, this does not solve the problem. Because, the exit function makes sure that main thread waits for the other threads to terminate.

But, in situations like signal generation, the default action is taken if signal handler is not present. I need to terminate only the thread that caused the signal and not all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apache: running multi-threaded or multi fork? Swakoo Linux - General 1 03-20-2008 07:18 AM
C/C++ Multi-Threaded Programming Debugging powah Programming 2 04-24-2006 07:03 PM
multi-threaded sliding window mjl3434 Programming 2 10-24-2005 04:16 PM
how to debug multi threaded application sibtay Programming 3 10-15-2004 12:02 PM
Multi-Threaded C pragti Programming 1 06-01-2004 10:50 AM


All times are GMT -5. The time now is 09:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration