Hello, i read some time ago a tread about counting semaphores and event flags. Is there something new about event flags and what would be the best way to do the counting semaphore? Thank you.
Sorry for the delay – other people normally respond before me but I guess I’m the only one that can answer this question. Event flags are not on the radar just yet, although they will be added when time permits. Counting semaphores on the other hand can be implemented easily with some small extensions to the binary semaphore implementation. Binary semaphores are implemented using a queue that can hold 1 item. Taking the semaphore removes the item from the queue, giving the semaphore places the item back in the queue. As there is only space for one item the semaphore is binary. If you created a queue with more spaces, then you have the effect of a counting semaphore. As an example, if you wanted a counting semaphore of 3, then create the queue with 3 spaces. Three tasks can then ‘take’ the semaphore before the queue is empty (no more semaphores available). [see the macro definitions within semphr.h, hopefully you can see how this simple mechanism works] The V4.5.0 adds a different type of mutex, and some new queue functionality. Regards.
Thank you. I have also sent you an email before I saw your answer hear. Sorry :) I’m checking that macros for binary semaphore and I’m already working on implementing a macro for couting semaphore. Mutexe is also a great feature and I must just say that the work you do one the kernel is really great. I just wish you won’t stop doing it :) Thanks again. Borut
Richard, one question regarding counting semaphores. When semaphore is created all resources are available in the begining. What must I do to have all resouces taken on the semaphore creation? It is very useful to have both options available, let say: vSemaphoreCreate( xSemaphoreHandleName, 128, 0 ); 128 is the maximum size and 0 means that none of the resources are available. or vSemaphoreCreate( xSemaphoreHandleName, 128, 128 ); 128 is the maximum size and 128 means that all of the resources are available. Thank you very much. Best regards, Borut
Just add a loop to ‘take’ the semaphore the required number of times either from you application code after the semaphore is created, or by extending the macro to do this within the create macro itself. This is what the binary semaphore create macro does, creates the semaphore then takes it before returning.
Is’t here an easier solution? Like setting something in the queue’s? Or is there too many things to do? Thank you
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.