This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: pthread_mutex_unlock when mutex is not locked
- From: RubÃn PÃrez de Aranda Alonso <rperez at sidsa dot es>
- To: ecos-discuss at sources dot redhat dot com
- Date: Wed, 27 Apr 2005 11:21:20 +0200
- Subject: Re: [ECOS] pthread_mutex_unlock when mutex is not locked
- Organization: SIDSA
- References: <426F4C4A.4020701@sidsa.es> <877jioipv1.fsf@osv.topcon.com>
I think the mutex is appropiate for the explained scenario.
The standard says:
"If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains
the concept of a lock count. When a thread successfully acquires a mutex
for the first time, the lock count is set to one. Every time a thread
relocks this mutex, the lock count is incremented by one. Each time the
thread unlocks the mutex, the lock count is decremented by one. When the
lock count reaches zero, the mutex becomes available for other threads
to acquire. If a thread attempts to unlock a mutex that it has not
locked or a mutex which is unlocked, an error will be returned."
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html
So, I think the unlock method must return an error code. In eCOS, this
method returns void. If we check the mutex is locked at least we avoided the
crash of the system.
RubÃn
Sergei Organov wrote:
RubÐn PÐrez de Aranda Alonso <rperez@sidsa.es> writes:
Hi all,
I have found a problem when I want to unlock a mutex that is not locked
by any thread.
Then the problem is in your code. The mutex is not appropriate for what
you are doing, -- only the thread that locked the mutex is allowed to
unlock it. Use something else, e.g., semaphore or condition variable to
achieve your goal.
--
______________________________________________________________
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