Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

pthread_exit() thread process is still on ps list

Posted on 2006-12-01
5
Medium Priority
?
404 Views
Last Modified: 2012-08-14
HI, I have a program I am threading. The main process spawns a thread that in turn spawns several other threads. Periodically I need the first thread to test if the multiple other threads have finished and if not to kill them and restart the list of threads. I have a signal handler that is catching my pthread_kill() call and then calling pthread_exit() from the thread, but I seem to just keep adding entries to the process list. Is there some other cleanup the 'parent' thread needs to do in order to remove the child thread from the process list?
0
Comment
Question by:PhilC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:billtouch
ID: 18056950
I got a bit confused at your explanation.  Can you post the relevant code here? I think you could be in some sort of a deadlock.

Bill
0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 2000 total points
ID: 18058570
You need to call pthread_join(3p) to actually make the thread go away. That's like a process calling wait(2) when a child exits.
How do you see there are extra processes? Vanilla ps or ps with a thread option? The old linux threads showed up with vanilla ps, but not Native Posix Tnhread Library (about libc-2.3.3 onwards). I'd recommend you move to NPTL if you haven't already done so.
0
 

Author Comment

by:PhilC
ID: 18068268
Linux 2.6.9...

  every few minutes I want my main thread to create several other threads that will do some work

//Parent
do
{
   current_time = time(&current_time);

    if (current_time - last_thread_connection_time > 60)//CHECK_CONNECTION_INTERVAL)
    {
       for(iIndex=0; iIndex<number_to_start_I; iIndex++)
      {
         pthread_create(&(*ptThreadArray[iIndex]), NULL, ConnectChildThreadFunc,(void*)iIndex);
      }
      last_thread_connection_time = time(&last_thread_connection_time);
   }
}while(1);

//child
static void *ConnectChildThreadFunc(void* arg)
{
...

return NULL;
}

One of my problems is how to know the child thread is done and not hanging. And how to kill it off from the parent if it is hanging. If I call pthread_join() on it and it is hanging then my main thread will hang too? no?

Thanks.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 18071796
Yes it will hang if the thread is stuck. But is that likely to happen once the code is fully debugged?
If you think you need to cater for it because of the nature of what the threads do, then you will indeed have to cater for it. A strategy could be: have one thread with the job of cleaning up successfully finishing threads. These finishing threads send a message to the cleaner thread as they are about to terminate; the cleaner thread then joins them. Have another thread to clean up the recalcitrants based say on a timeout. This scavenger thread would kill off these threads, maybe first with SIGTERM and later with SIGKILL or maybe just SIGKILL right off.
Sounds like wrting parts of an operating system? That's thread programming.
0
 

Author Comment

by:PhilC
ID: 18072227
lol thanks. I ended up putting an alarm in the child threads and if they are not finished then BAM! Force them to.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question