From: "Neundorf, Alexander" <Alexander.Neundorf@jenoptik.com>
To: <ecos-discuss@ecos.sourceware.org>
Subject: [ECOS] correct handling of condition variables from DSRs
Date: Mon, 22 May 2006 15:37:00 -0000 [thread overview]
Message-ID: <5A8A17126B73AC4C83968F6C4505E3C5042D0FA1@JO-EX01.JENOPTIK.NET> (raw)
Hi,
the eCos docs say that condition variables can be signalled also from DSRs. Usually, in order to signal a change, the following code is required:
cyg_mutex_lock(&condition_mutex)
// ... modify the data
cyg_cond_signal(&condition_var);
cyg_mutex_unlock(&condition_mutex);
When doing this from a DSR, the mutex can't be locked, so I only can do:
cyg_cond_signal(&condition_var);
In order to receive the signal, usually I would:
cyg_mutex_lock(...);
cyg_cond_wait(...);
...
cyg_mutex_unlock();
Now this isn't synchronized with the DSR. The mutex docs say that cyg_scheduler_lock() has to be used, so it becomes:
cyg_scheduler_lock();
cyg_mutex_lock(...);
cyg_cond_wait(...);
...
cyg_mutex_unlock();
cyg_scheduler_unlock();
But the same protection has to be used when signalling from a thread, since otherwise the DSR could modify the data which are only protected by the mutex, right ?
So in order to signal the condition correctly from a thread I have to do the following:
cyg_scheduler_lock();
cyg_mutex_lock(&condition_mutex)
// ... modify the data
cyg_cond_signal(&condition_var);
cyg_mutex_unlock(&condition_mutex);
cyg_scheduler_unlock();
But since now all three participants (sender from DSR, sender from thread, receiver) are all synchronized using cyg_scheduler_lock(), do I actually still need the mutex at all ? Or can I simply ignore it ?
Bye
Alex
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
next reply other threads:[~2006-05-22 15:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-22 15:37 Neundorf, Alexander [this message]
2006-05-23 4:49 ` [ECOS] " Sergei Organov
2006-05-23 5:48 ` Fabian Scheler
2006-05-23 6:22 ` Sergei Organov
2006-05-23 6:26 ` Fabian Scheler
2006-05-23 6:49 ` 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=5A8A17126B73AC4C83968F6C4505E3C5042D0FA1@JO-EX01.JENOPTIK.NET \
--to=alexander.neundorf@jenoptik.com \
--cc=ecos-discuss@ecos.sourceware.org \
/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).