Queues and Semaphores

bonanza35 wrote on Wednesday, January 07, 2009:

We’re in a severe RAM crunch on a project, and are looking for ways to free up some RAM.  There are some places where queues are used where they aren’t really needed, and semaphores would work just as well.  So, I started looking at the effects of replacing a few queues with semaphores.

Then I discovered that a semaphore is just another kind of queue, and the memory overhead is the same (76 bytes, IIRC).

Isn’t there a better way to implement semaphores that won’t use up quite as much memory?

edwards3 wrote on Wednesday, January 07, 2009:

There it is just a trade off between ROM and RAM. Semaphores are implemented so they add nothing to the code size by reusing the queue. Semaphores are free as far as ROM is concerned.

Most of the RAM overhead is part of the event control. That is how the tasks are blocked and unblocked. Some RTOS use separate semaphore and event control structures, but add the two together and there is the same usage.

dmitrycherepanv wrote on Thursday, January 08, 2009:

Year ago I had such question too. And I had try to write a binary semaphore.
You can see it on http://freertos.narod.ru/.

It use less ram. Actually it consist only from one List. This mean that xList == xMySemaphoreImplementationStructure.

It is a pity but I did not test it very well, but this variant of semaphores worked in PC demo tests instead of original variant.  So you can try to use it. May be Richard or somebody else will do some attention to this sources.