This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: ecos state machine
- From: NavEcos <ecos at navosha dot com>
- To: ? ? <johnsonest at hotmail dot com>,nickg at calivar dot demon dot co dot uk
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Wed, 14 Aug 2002 05:48:09 -0700
- Subject: Re: [ECOS] ecos state machine
- References: <F114YZgy86aezUF0d0H00005221@hotmail.com>
- Reply-to: ecos at navosha dot com
This has been answered a few times, but nobody pointed out
explicity your errors in your code.
On Tuesday 13 August 2002 22:19, ? ? wrote:
> hi,nickg!
> mail box in ecos maybe unsafe :
> char *msg="hello!nickg";
> cyg_mbox_put(mbox,(void*)msg);
> ...
> free(msg);
> return //danger:if now msg has not yet received.
First, it may not be immediately obvious that mailboxes do not copy
data, they just pass pointers from one thread to another. Here you
have declared "msg" as a stack based variable. Allocate the space
for it dynamically.
Second, you are freeing "msg" at the end, which wasn't dynamically
allocated.
This (might) be more sensible
thread1:
char *msg = (char *)malloc (100);
sprintf (msg, "hello! nickg");
cyg_mbox_put (mbox, (void*)msg);
thread2:
char *msg;
msg = cyg_mbox_get (mbox);
if (msg != NULL)
{
printf ("Received message %s\n",msg);
free (msg);
}
> From: Nick Garnett <nickg@calivar.demon.co.uk>
>
> >To: ÕÅ ÁÁ <johnsonest@hotmail.com>
> >CC: ecos-discuss@sources.redhat.com
> >Subject: Re: [ECOS] ecos state machine
> >Date: 07 Aug 2002 12:33:58 +0100
> >
> >ÕÅ ÁÁ <johnsonest@hotmail.com> writes:
> > > hi,nikg!
> > > i have a question to consult you:
> > > In ecos,why thread_data_map was defined as "static" type?
> > > so all threads share this variable,just like global variable in
>
> C,right?
>
> >[Please remember to copy all messages to the ecos-discuss list. That
> >way others can benefit from the discussion and it will be archived for
> >future reference.]
> >
> >The intended use of the per-thread data is that a slot that is
> >reserved by a library or some other component does so for all
> >threads. Hence the map must be global.
> >
> >--
> >Nick Garnett -
>
> _________________________________________________________________
> Ãâ·ÑÏÂÔØ MSN Explorer: http://explorer.msn.com/lccn/
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss