Semaphore pending ?

delphes wrote on Wednesday, October 31, 2018:

Dear All,

I have a task1 like this :

for (;;) {
     xSemaphoreTake(XSemSend, portMAX_DELAY);
   // doing some consuming process
   }

in few other tasks during the consuming process of task1 I can have xSemaphoreGive (XsemSend); let’s say 6 times. I discovered that when the consuming process is done and it goes to SemaphoreTake waiting it immediately going again to consuming process, but only no more than 3 times, is this normal or not?

   Thanks and Rgds
   David

rtel wrote on Wednesday, October 31, 2018:

Sorry - I don’t understand your question. Are you saying that if you
give a semaphore 6 times you would expect to be able to take it 6 times
too? That would only be the case if the semaphore was created as a
counting semaphore with the max count parameter set to 6 or greater.

https://www.freertos.org/CreateCounting.html

delphes wrote on Thursday, November 01, 2018:

Dear Richard,

The Semaphore was created with xSemaphoreCreateBinary() so maxcount is 1 I believe, so if I have :

task1
for (;:wink: {
xSemaphoreTake(XSemSend, portMAX_DELAY);
// doing some consuming process consuming 1 sec
}

task2
for (;:wink: {
xSemaphoregive((XSemSend);
vTaskDelay(100);
count++;
if( count == 10) vTaskDelete(NULL);
}

task1 should wakeup only one time ?

fizzyaid wrote on Thursday, November 01, 2018:

Task 2 is giving the semaphore back after 100ms which means Task1 can take it again.

delphes wrote on Thursday, November 01, 2018:

yes of course but task 1 is busy during 1 sec so IMO it should not take again

fizzyaid wrote on Thursday, November 01, 2018:

You have a logic (pattern) problem.

This will execute at least twice according to what you’ve posted, possibly more times depending on how quickly task 1 processes its data.