[uClibc] Mutex and detached thread problem

Christian Magnusson christian.magnusson at runaware.com
Wed Jan 26 18:03:43 UTC 2005


Could somebody else this example program that I wrote for my Coldfire
M5206eC3 board. It shows two major problem I have with mutexes and
detaching a new thread at once in pthread_create().
It's very annoying when porting applications and I have to rewrite much
code with ifdef's all the time.

I don't know if the problem is caused by a bad compiler, buggy uClibc
or buggy kernel.
I have used uClinux-dist-20041215 with 2.4.27-uc1 kernel and

gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from
http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from
http://www.snapgear.com/)

/Christian


--------
Mutexes doesn't work unless I either call pthread_mutexattr_settype()
or just link the binary with it unused?!?
--------
pthread_attr_init(&attr);
pthread_attr_setdetachstate();
pthread_create( &thread, &attr, function, NULL );
-------- (This hangs the application with a zombie process)

-------- but this works...
pthread_create( &thread, NULL, function, NULL );
pthread_detach(thread);
--------
Any idea?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: test8.c
Type: text/x-c
Size: 4791 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20050126/cf573941/attachment.bin 
-------------- next part --------------
/> test8 0
Detach new thread after pthread_create()
Set mutex type to PTHREAD_MUTEX_ADAPTIVE_NP
ACCEPTLOCK
create new thread
ThreadedAccept
detach thread
new thread detached
ACCEPTUNLOCK
ACCEPTLOCK
create new thread
detach thread
new thread detached
ThreadedAccept
ACCEPTUNLOCK

------------------------------------------

/> test8 1
Detach new thread after pthread_create()
Let mutex stay initialized to PTHREAD_MUTEX_INITIALIZER
ACCEPTLOCK
create new thread
detach thread
new thread detached
ACCEPTLOCK
create new thread
ThreadedAccept
ThreadedAccept
detach thread
new thread detached
ACCEPTLOCK
...... etc....
ThreadedAccept
ThreadedAccept
ThreadedAccept
ACCEPTUNLOCK
ACCEPTUNLOCK
ACCEPTUNLOCK
ACCEPTUNLOCK
ACCEPTUNLOCK
ACCEPTUNLOCK


------------------------------------------

/> test8 2
Set detach state to PTHREAD_CREATE_DETACHED at once at pthread_create()
Set mutex type to PTHREAD_MUTEX_ADAPTIVE_NP
ACCEPTLOCK
create new thread

/> ps -ef
  284 root            SW  test8 2
  285 root            Z   [test8]



More information about the uClibc mailing list