This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: About Flags
- To: ecos-discuss at sourceware dot cygnus dot com
- Subject: Re: [ECOS] About Flags
- From: Hugo Tyson <hmt at redhat dot com>
- Date: 06 Oct 2000 13:31:38 +0100
- Newsgroups: cygnus.sourceware.ecos.d
- Organization: Red Hat UK
- References: <8AE4B526B977D411841F00A0CC334020052C7A@cuz-exchange.sdesigns.net>
- Reply-To: ecos-discuss at sources dot redhat dot com
Fabrice Gautier <Fabrice_Gautier@sdesigns.com> writes:
> Hi,
>
> I would like to know if it is safe to destroy a flag structure after it has
> been signaled.
>
> I mean:
>
> I have several thread waiting for the flag - and they know that after wait
> return the flag pointer they have will be invalid.
> And one thread signaling the flag and then deleting it.
>
> So is it possible that between the moment the corresponding cyg_flag_setbits
> returns and the moment cyg_flag_wait returns the cyg_flag_wait function try
> to access the flag structure ?
You can just call the destructor. Cyg_Flag::~Cyg_Flag() awakens all waiting
threads with wake reason Cyg_Thread::DESTRUCT, so they know the flag is
gone, and return false. If you signalled some threads before that, they
will no longer be waiting, all will be well: they will not try to touch the
flag structure.
> Additionnaly, I would like to wait for an exact value of the flag, is this
> possible? It seems only supported operations are AND and OR.
No; flags aren't like that. If you're placing arbitrary values in there
(such as an address or a count) you're using them inappropriately.
You can choose just to put in a limited range of values of course. If you
use only 1,2,4,8,16.... then either wait opt picks up a unique value.
- Huge