Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 7 months ago.
Semaphore behavior (no semaphore count limit)
Hi!
I want to create a counting semaphore (with a count value of 1 (binary)) but since there is no check whether initial count has been reached the semaphore counter continues to increment with each call to release. According to the Producer/Consumer problem the consumer must wait for the producer to produce something if the queue is empty and the producer must wait for the consumer to consume something if the queue is full. However it seems the queue is only considered "full" as the counter reaches osFeature_Semaphore (default value 65535) and returns osErrorResource.
Does anyone know if it is even possible to create a counting semaphore with an actual limit (other than osFeature_Semaphore) in mbed rtos?
1 Answer
9 years, 7 months ago.
You could use 2 semaphores. One to track the number of empty items for the producer to fill and another to track the number of active items that the consumer can consume. The empty count semaphore would be initialized to the number of total items in your queue, the producer would wait on this semaphore, and the consumer would signal it. The active semaphore would be initialized with a count of 0, the consumer would wait on this semaphore, and the producer would signal it.