|Summary:||ASTERISK-12662: [patch] POSIX thread operations errors|
|Date Opened:||2008-08-29 09:50:40||Date Closed:||2008-10-30 15:22:40|
|Environment:||Attachments:||( 0) chan_h323.patch|
|Description:||POSIX thread functions pthread_cancel, pthread_kill and pthread_join are called with thread IDs belonging to monitor threads that (may) have ended.|
|Comments:||By: Tilghman Lesher (tilghman) 2008-08-29 10:25:49|
You're going to have to be more explicit. Exactly how could those threads have ended, without changing the value of the stored pthread id?
By: Tilghman Lesher (tilghman) 2008-08-29 10:27:26
Additionally, if you're reporting a crash, you MUST upload a stack backtrace, as detailed in doc/backtrace.txt.
By: matti (matti) 2008-08-30 00:28:35
A hardware or compiler failure could make the detached do_monitor function thread end prematurely, after which the dynamic memory associated with the thread ID can be freed. Detachment and pthread_cancel allow the dynamic memory associated with the thread ID to be freed, after which the POSIX thread functions pthread_kill and pthread_join calls with the thread ID in function unload_module are errors.
By: Tilghman Lesher (tilghman) 2008-08-30 08:56:27
And given a hardware or compiler failure, how are we supposed to work around that in software?
By: Tilghman Lesher (tilghman) 2008-08-30 08:59:07
I think we've gone beyond the point of utterly ridiculous scenarios. Unless you can demonstrate a SPECIFIC code defect (not a hardware or a compiler defect), this issue is closed. Please do not open similar issues.
By: matti (matti) 2008-08-31 05:09:40
The specific code defect is that POSIX thread operations are done on threads after the detached threads have been cancelled, or in the unlikely case of hardware, compiler or operating system failure, abnormally ended. After a detached thread has ended, the dynamic memory allocated to it can be freed. Therefore, memory faults can occur. Cancelling a thread allows its dynamic memory to be freed.
By: Sean Bright (seanbright) 2008-09-02 14:32:34
If you are able to submit a patch to address the issues you mention, please re-open this bug. Based on the feedback received so far, there doesn't appear to be any actionable items here.
By: matti (matti) 2008-09-29 08:27:08
This can be easily fixed by not detaching the monitor thread.
By: Sean Bright (seanbright) 2008-09-29 08:34:42
Could you attach a patch which we can review?
By: Tilghman Lesher (tilghman) 2008-09-30 11:11:17
Since you're reporting a crash, I need to see this specific crash in trunk (NOT 1.2, as you previously reported) with the code as written. We've already shown that there was a defect in the 1.2 code, and demonstrated a reasonable explanation which conflicted with your theory, so you need to show us a crash which aligns with your explanation.
By: matti (matti) 2008-10-01 04:09:36
I have not tested trunk but I have a theoretical explanation why the code is wrong. The POSIX standard forbids the use of thread IDs after they have been detached and ended. You should not count on your luck that the implementations of POSIX threads do not crash as a result of the violations.
By: Tilghman Lesher (tilghman) 2008-10-01 09:39:52
The POSIX standard says no such thing about the use of the thread ID for use with pthread_cancel or pthread_kill, only for the use of pthread_join. See http://opengroup.org/onlinepubs/007908799/xsh/pthread_attr_setdetachstate.html
If you can find a source for your assertions within the opengroup.org website, I'd be happy to see it.
By: matti (matti) 2008-10-01 23:53:24
The driver calls also pthread_join after calling pthread_cancel, which is an error also according to http://opengroup.org/onlinepubs/007908799/xsh/pthread_attr_setdetachstate.html.
The following link is a source: "The pthread_detach() function shall indicate to the implementation that storage for the thread thread can be reclaimed when that thread terminates."
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
By: Digium Subversion (svnbot) 2008-10-30 15:22:37
r152958 | tilghman | 2008-10-30 15:22:36 -0500 (Thu, 30 Oct 2008) | 3 lines
Cannot join detached threads. See http://www.opengroup.org/onlinepubs/000095399/functions/pthread_join.html
(Closes issue ASTERISK-12662)