public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Nick Garnett <nickg@ecoscentric.com>
To: "Rubén Pérez de Aranda Alonso" <rperez@sidsa.es>
Cc: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] pthread_mutex_unlock when mutex is not locked
Date: Wed, 27 Apr 2005 11:51:00 -0000	[thread overview]
Message-ID: <m3acnktsak.fsf@xl5.calivar.com> (raw)
In-Reply-To: <426F5990.5060105@sidsa.es>

Rubén Pérez de Aranda Alonso <rperez@sidsa.es> writes:

> 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.

eCos doesn't currently support recursive mutexes -- partly because
some of us consider them the work of the devil and partly because it
would require some significant work on the kernel mutex code to make
it work smoothly with the priority inversion protocols.

DSRs are not threads, and can be called in the context of any thread
in the system. Calling mutex unlock from a DSR would do it in the
context of the thread that happened to running when the interrupt
occured. If you are lucky, this will be the thread that locked the
mutex and it will work. If you are unlucky, it will be a different
thread and the mutex will not get unlocked.

Condition variables can be signalled from DSRs and you should really
use one of those to wake up any threads.


-- 
Nick Garnett                                     eCos Kernel Architect
http://www.ecoscentric.com                The eCos and RedBoot experts


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

  parent reply	other threads:[~2005-04-27 10:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-27  8:30 Rubén Pérez de Aranda Alonso
2005-04-27  9:00 ` Sergei Organov
2005-04-27  9:54   ` Rubén Pérez de Aranda Alonso
2005-04-27 10:18     ` Andrew Lunn
2005-04-27 11:51     ` Nick Garnett [this message]
2005-04-27 12:38       ` Rubén Pérez de Aranda Alonso
2005-04-27 13:44         ` Sergei Organov
2005-04-27 14:37           ` Rubén Pérez de Aranda Alonso
2005-04-28 10:15         ` Nick Garnett
2005-04-29 13:49           ` Rubén Pérez de Aranda Alonso
2005-04-27 12:15     ` Sergei Organov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3acnktsak.fsf@xl5.calivar.com \
    --to=nickg@ecoscentric.com \
    --cc=ecos-discuss@sources.redhat.com \
    --cc=rperez@sidsa.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).