Skip to contentSkip to conversation

Use semaphore for producer/consumer case...

DISCUSSION Manfred Spraul 2 participants 4 messages Mar 23, 2001 – Mar 27, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines
     consumer()

            /* Let's wait for 10 items */
            atomic_set(&sem->count, -10);

That doesn't work, at least the i386 semaphore implementation doesn't support semaphore counts < 0.

--
Manfred

#1 lore raw
Quoted 7 lines · Manfred Spraul
Quoted 4 lines
     consumer()

            /* Let's wait for 10 items */
            atomic_set(&sem->count, -10);

That doesn't work, at least the i386 semaphore implementation doesn't support semaphore counts < 0.

Does that mean that kernel semaphore can not be used for something else than mutual exclusion ?

Stelian.

Signature · 4 lines
Stelian Pop <[email protected]>
|------------- Ingénieur Informatique Libre --------------|
| Alcôve - http://www.alcove.com - Tel: +33 1 49 22 68 00 |
|----------- Alcôve, l'informatique est libre ------------|
#2 lore raw
In reply to Manfred Spraul

From: "Stelian Pop" <[email protected]>

Quoted 2 lines
Quoted 2 lines

That doesn't work, at least the i386 semaphore implementation

doesn't

Quoted 5 lines
Quoted 1 line

support semaphore counts < 0.

Does that mean that kernel semaphore can not be used for something else than mutual exclusion ?

It's a bit better: counts >= 0 are supported, i.e. you can call up() before down(), and that's used in several places.

The for loop that Nigel proposed should solve your problem. Multiple up's are handled correctly.

--
Manfred

#3 lore raw
In reply to Manfred Spraul
Quoted 9 lines · Manfred Spraul
Quoted 1 line
Quoted 1 line

That doesn't work, at least the i386 semaphore implementation

doesn't

Quoted 5 lines
Quoted 1 line

support semaphore counts < 0.

Does that mean that kernel semaphore can not be used for something else than mutual exclusion ?

It's a bit better: counts >= 0 are supported, i.e. you can call up() before down(), and that's used in several places.

I see... it's somewhat different than the classical semaphore implementation, but usable anyway.

Quoted 2 lines

The for loop that Nigel proposed should solve your problem. Multiple up's are handled correctly.

Now I understand his suggestion. Thanks to both of you.

Stelian.

Signature · 4 lines
Stelian Pop <[email protected]>
|------------- Ingénieur Informatique Libre --------------|
| Alcôve - http://www.alcove.com - Tel: +33 1 49 22 68 00 |
|----------- Alcôve, l'informatique est libre ------------|