[ECOS] About Flags
Hugo Tyson
hmt@redhat.com
Fri Oct 6 05:45:00 GMT 2000
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
More information about the Ecos-discuss
mailing list