[uClibc] Failing pthread_mutex_lock() on Coldfire

Christian Magnusson christian.magnusson at runaware.com
Tue Sep 7 15:18:39 UTC 2004


Hi list...

I have ported fuse and owfs to uClinux. I'm basically using the
snapgear-3.1.1 distribution with 2.4.24-uc0 kernel and
uClibc-0.9.26 on a Coldfire M5206eC3 board.

There are 10 temperature sensors and one LCD display connected
to a 1-wire bus (via the serial port) which is mounted as a
file-system with owfs and fuse. Reading a temperature sensor takes
about one second, and all other threads trying to access the serial
port during that time should be blocked of course.

When owfs became multi-threaded I noticed some problems with
mutexes that didn't work as they should. The applications work
on normal linux servers, so I suppose the problem come from
uClinux/uClibc.

I also noticed that Coldfire doesn't have any atomic Compare And Swap
instruction, and I am worried that this could be the reason
to why 2 threads can lock a mutex at the same time.

My main question is:  Is it safe to use mutexes and semaphores
on a Coldfire processor running uClinux?



pthread_mutex_init(&lock, NULL);
initiate a mutex to the type PTHREAD_MUTEX_TIMED_NP, and this
type doesn't work good at all. It works in a simple example
application, but not in my case with fuse/owfs. pthread_mutex_lock
never seem to wait for an unlocked mutex.
This results into two threads writing to the serial port at the
same time, and everything fails.

When I change the mutexes to PTHREAD_MUTEX_ADAPTIVE_NP it seems
to work much better, but it's far from perfect. Most of the
reading and writing to the serial-port are protected with the
mutex, but after an hour or so some failing pthread_mutex_lock
give me a collision again.


I read an old posting about replacement to the missing CAS instruction,
but it doesn't seem to be a very nice solution.
Using a trap-vector to do the test and set could perhaps work, but
it will probably take a long time to execute and interrupt the kernel
very much. Is this any solution to think about?
http://mailman.uclinux.org/pipermail/uclinux-dev/2002-September/010753.html


Can anyone tell me if there are some hardware limitations on my
Coldfire processor, or if it could be fixed by changing the way
I currently use mutexes ?

/Christian






More information about the uClibc mailing list