[haiku-development] Re: Calling pthread_join on a detached pthread

  • From: Jason Whitehorn <jason.whitehorn@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 5 Aug 2012 09:21:36 -0500

On Sun, Aug 5, 2012 at 8:54 AM, Rene Gollent <anevilyak@xxxxxxxxx> wrote:
>
>
> When pthread_detach() is called, the thread structure associated with
> it is freed. As such, if you then call pthread_join() on the same
> structure, you're asking the latter to operate on already freed
> memory, hence the crash.
>
> Regards,
>
> Rene
>
>
Thank you for your reply.

That is my understanding as well, that the free in `join` is trying to
release an object was was previously freed.

I guess my confusion was that I was going off of an old POSIX document that
lead me to believe that pthread_join should safe guard against this
condition by returning EINVAL, as opposed to crashing.

I now see that I was going against an outdated document.

I guess this conversation ties into ticket #61 (
https://dev.haiku-os.org/ticket/61), which discusses building a POSIX test
suite.

The test suite I was using was the one from
http://sourceforge.net/projects/posixtest/, and it raises this condition of
calling pthread_join on a detached thread to see what the underlying OS
does. The patch I submitted prevented the crash, and resulted in this
particular test case to pass.

Perhaps this test suite is outdated as well... that is part of what I am
trying to understand.

Other related posts: