This is the mail archive of the ecos-discuss@sourceware.org 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: Once again, I need a binary semaphore


On 2015-03-17, lesc <lesc@zhaw.ch> wrote:
>
>
> On 16.03.2015 18:17, Grant Edwards wrote:
>> Once again, I find I need a binary semaphore for a C application I'm
>> porting from another OS.

> And just using a mutex is not a option? (Sorry if you allready ruled 
> that out, but you didn't metion why youd need that specific
> sync-mechanism).

The Semaphore is used so that one thread can wait for completion of a
task that was farmed out to different thread: Thread A waits on the
semaphore until thread B posts.  It's an inter-thread signalling
mechanism, not a mutual-exclusion mechansim.

I'm not sure why a counting semaphore wasn't used by the applications
author.  I haven't analyzed all of the possible execution paths, but
the original author of the application very specifically chose to use
a binary semaphore instead of a counting semaphore, and it seemed
wisest not to change things without a good reason.  It took a
half-hour to implement a C API for binary semaphores, it could take
weeks to analyze tens of thousands lines of third-party code to see if
a counting semaphore would work the same as a binary semaphore in all
the corner cases.

-- 
Grant Edwards               grant.b.edwards        Yow! I guess you guys got
                                  at               BIG MUSCLES from doing too
                              gmail.com            much STUDYING!


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


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