Summary:ASTERISK-02441: Linking wrong threads library and other threads issues
Reporter:jacs (jacs)Labels:
Date Opened:2004-09-21 09:47:28Date Closed:2008-01-15 15:08:21.000-0600
Versions:Frequency of
Environment:Attachments:( 0) asterisk.diff
( 1) asterisk2.diff
( 2) Makefile.diff
Description:The top level makefile syntax is wrong for selecting the correct threads library for FreeBSD 5.2 and above. It links the rentrant c library by mistake. Changing this so it picks up the POSIX threads library results in "almost" all known issues to go away. ie moh, conferencing etc working out of the box.

However, daemon mode stops working. I tracked this down to
ast_pthread_create(&lthread, NULL, listener, NULL) not liking test_for_thread_safety() to have been run in asterisk.c. If you change daemon to output error messages to console you get

Fatal error 'mutex is on list' at line 516 in file /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 0)

when it tries to create the listener thread. It needs someone with better threads understanding than me to sort that out.

Attached is update for Makefile and a work around patch for the daemon problem.

Comments:By: jacs (jacs) 2004-09-22 03:41:31

There appears to be a bug in the pthread library on FreeBSD. If a thread is created before a call to daemon then any threads created after the daemon call will generate an abort from the threads library. I have sent some sample code to the  freebsd threads list. I can't see why the test_for_thread_safety() call could not be performed after the daemon call as a work around?


By: jacs (jacs) 2004-09-22 10:01:07

From the threads gurus .... you should not perform any POSIX thread work before the daemon() call as it calls fork() and closes the parent process down. In asterisk2.diff I have moved test_for_thread_safety() below the daemon() call as this makes no functional difference but will stop the threads issure.

Please could someone add Makefile.diff and asterisk2.diff to the CVS head.


By: jacs (jacs) 2004-09-28 10:47:09

Reminder sent to markster


Any chance that Makefile.diff and asterisk2.diff could be added from this bug report. It will not impact on Linux.

By: Mark Spencer (markster) 2004-09-28 13:09:03

Fixed in CVS, thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:08:21.000-0600

Repository: asterisk
Revision: 3850

U   trunk/Makefile
U   trunk/asterisk.c

r3850 | markster | 2008-01-15 15:08:21 -0600 (Tue, 15 Jan 2008) | 2 lines

Fix threads in FreeBSD (bug ASTERISK-2441)