This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Deleting a semaphore


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]