This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Deleting a semaphore
- From: Nick Garnett <nickg at ecoscentric dot com>
- To: "Daniel Lidsten" <Daniel dot Lidsten at combitechsystems dot com>
- Cc: "ecos-discuss" <ecos-discuss at sources dot redhat dot com>
- Date: 30 Jun 2003 08:43:27 +0100
- Subject: Re: [ECOS] Deleting a semaphore
- References: <004B1D7A5257174C9044A1B7BD0E60EDA65E0F@ratatosk.combitechsystems.com>
"Daniel Lidsten" <Daniel.Lidsten@combitechsystems.com> writes:
> Hi,
>
> Is there any way to see which (if any) threads that are pending for a
> semaphore? If it doesnt then it seems dangerous to remove/destroy a
> semaphore if it maight hang the system. The peek operation will only
> work to make such check if the init value was above zero.
>
Given that you are about to destroy it, it does not matter what value
the semaphore ends up with, so the following should get all waiting
threads running:
while( cyg_sem_peek( sem , val ), val <= 0 )
{
cyg_sem_post( sem );
cyg_thread_delay( 1 );
}
cyg_sem_destroy( sem );
The delay is there to allow lower priority threads to exit their waits
cleanly.
Obviously you need some other mechanism to tell the awakened threads
that this is the last wakeup and make them stop using the semaphore.
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss