[ECOS] pthread_mutex_unlock when mutex is not locked

Rubén Pérez de Aranda Alonso rperez@sidsa.es
Wed Apr 27 08:30:00 GMT 2005

Hi all,
I have found a problem when I want to unlock a mutex that is not locked
by any thread. This scenario can be needed when we want to signal
a resource in hardware is free from a DSR, that is executed by a
peripheral interrupt, to threads that requires the access to this
resource. The thread will execute a lock before access to resource.
The DSR will be executing an unlock for each HW interrupt although
there aren't threads accessing to the resource.
I think the mutex must verify the lock condition before perform
an unlock operation.
I have added the next code in Cyg_Mutex::unlock(void) method:

    // ---------------------
    if (!locked)
    // ---------------------

This scenario can also be solved using message queues or semaphores.
I prefer mutexes because the unlock condition is when their count
is equal to zero, and, in semaphores, the unlock condition is when
their count is > 0.




Rubén Israel Pérez de Aranda Alonso
SIDSA - Semiconductores Investigación y Diseño S.A.
Parque Tecnológico de Madrid           Phone : +34 91 803 5052
C/ Torres Quevedo, nº 1                Fax:    +34 91 803 9557
28760 TRES CANTOS (Madrid) (SPAIN)
e-mail: rperez@sidsa.com               www.sidsa.com

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list