From: Bart Veer <bartv@ecoscentric.com>
To: gorjup@norik.com
Cc: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] Two threads -two messages - one mbox
Date: Sun, 20 Jun 2004 17:32:00 -0000 [thread overview]
Message-ID: <20040620173214.572C4EC1C0@delenn.bartv.net> (raw)
In-Reply-To: <200406201844.40331.gorjup@norik.com> (message from Matthias Gorjup on Sun, 20 Jun 2004 18:44:40 +0200)
>>>>> "Matthias" == Matthias Gorjup <gorjup@norik.com> writes:
Matthias> Hello,
Matthias> I am having problems with sending more than on
Matthias> mbox-meassage in one loop-iteration from one thread to
Matthias> another. Below is the code we are using:
<snip>
Matthias> If I only send one message and read one mesage, the code
Matthias> works fine. But if I send two messages in one iteration,
Matthias> the system reboots after the first iteration of the
Matthias> sending thread.
Matthias> I must say that I need to send two integer values from
Matthias> one thread to another during one iteration and the other
Matthias> thread needs to read both of them in one iteration as
Matthias> well.
Matthias> What could be wrong?
Matthias> Should I use a global structure with two integer
Matthias> elements and then send only a pointer to that structure
Matthias> (this would make it possible to send only one message in
Matthias> one iteration)? Should I use mutex-es or some other
Matthias> synchronizaiton mechanism?
I can see two obvious problems with your code.
1) you are creating and starting the threads before the
synchronization data structures. In particular mbox_handle could
get used by thread1() or thread2() before main() has created it. In
your simple example code main() is likely to run at a higher
priority then the other threads so there is not actually a problem,
but that is likely to change as the code gets more complicated. It
is a good idea to initialize all synchronization data structures
before starting any threads.
2) you are not allocating any space for the mbox itself. Your sock_msb
argument to cyg_mbox_create() is an uninitialized pointer so it
will have a value of 0. Hence you are placing the mbox at location
0, where the interrupt vectors are likely to be depending on the
architecture you are using.
I suspect that when you do the second mbox send you are overwriting
a critical interrupt vector, and the next time an interrupt
triggers the system will crash and burn.
Instead you need to allocate space for the mbox, something like:
cyg_handle_t mbox_handle;
cyg_mbox mbox_data;
...
int
main(int argc, char** argv)
{
cyg_mbox_create(&mbox_handle, &mbox_data);
/* now create and start the threads */
}
Bart
--
Bart Veer eCos Configuration 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
next prev parent reply other threads:[~2004-06-20 17:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-20 16:51 Matthias Gorjup
2004-06-20 17:32 ` Bart Veer [this message]
2004-06-21 17:46 ` Matthias Gorjup
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=20040620173214.572C4EC1C0@delenn.bartv.net \
--to=bartv@ecoscentric.com \
--cc=ecos-discuss@sources.redhat.com \
--cc=gorjup@norik.com \
/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).