[Bug 1731] pthread_join() returns ESRCH if target thread already terminated

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Wed May 25 09:01:31 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1731

Frederic Brault <frederic.brault at kalray.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frederic.brault at kalray.eu,
                   |                            |marta.rybczynska at kalray.eu

--- Comment #2 from Frederic Brault <frederic.brault at kalray.eu> 2011-05-25 04:01:30 CDT ---
The attached patch tries to solve this issue.

More specifically, here is a short description of the problem :

When a thread exits, it calls _Thread_Close, which invalidates its object_id
and removes the object. If another thread had tried to join this thread before
it exits, it will be put in its Join_List queue, and notified upon exit.
But if a thread tries to join another thread after it has exited, then the
object_id has been invalidated, and ESRCH is returned.

To sum it up : in RTEMS, you can only join a thread before it has exited. This,
of course, is a problem.

The patch tries to solve this issue by creating a new function,
Thread_Terminate.
This function does most of what Thread_close does, but without deleting the
object and object Id of the thread. It will be up to the joining thread to do
this cleanup.

One problem with this is that unjoined thread will create objects which linger
in memory aka "zombies". But it is up to the programmer to make sure that this
does not happen.

Some additional comments about the patch :

- I created a TERMINATED state. Not sure this is mandatory, DORMANT state might
be enough. 
- Also, I am not entirely satisfied with having to duplicate Thread_Close in
Thread_Terminate. There might be a better refactoring option.
- Last, The patch uses Lock/Unlock critical section, and thus depends upon PR
1809. In a non-smp setting, this can be removed.

Comments are highly welcomed

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list