[En-Nut-Discussion] NutSemTryWait Bug
Matthias Ringwald
mringwal at inf.ethz.ch
Mon Jun 16 17:08:02 CEST 2008
Hi "thezachariasgroup"
On 16.06.2008, at 16:23, ennut at thezachariasgroup.com wrote:
>
> I think I found a problem in NutSemTryWait in NUT\OS\semaphore.c
>
> Original Code:
>
> int NutSemTryWait(SEM * sem) {
> if (sem->value < 0)
> return -1;
> else
> NutSemWait(sem);
> return 0;
> }
>
> Suggested code:
>
>
> int NutSemTryWait(SEM * sem) {
> if (sem->value <= 0)
> return -1;
> else
> NutSemWait(sem);
> return 0;
> }
>
> If the sem->value was initialized to 1, and a routine has grabbed
> it, sem->value would be zero.
> NutSemTryWait should return a -1 under these conditions since the sem
> is not available.
> However sem->value is not less than zero and the code calls
> NutSemWait and waits for the sem to become free.
> This is not the intent of the routine as I understand it.
>
> Thoughts?
Yeah. You're right. Thanks for spotting this, I'll fix it in CVS HEAD
now.
Regards
Matthias
More information about the En-Nut-Discussion
mailing list