Re: Task goes into a Pend+I state : Semaphore issue?



Hi kapslock,
This seems to be a standard producer consumer
problem.The common resource to be protected is the queue of commands.
This is the problem of synchrnonization and not mutual exclusion.Hence
opt for binary semaphore.This should fix the inheritance problem.
This can be solved not with one but with two semaphores.That would be
the perfect solution independent of scheduling policy and
priorities.Soln

Go for two semaphores: SA governed by task A,initial value =1
SB governed by task B,initial value
=0
Inside the code for task A:

semTake(SA)
put the cmd in the queue.
semGive(SB)

Inside the code for task B:

semTake(SB)
put the cmd in the queue.
semGive(SA)

This would give the perfect solution avoiding all kind of race
conditions.

The issue in previous case 'could be' because of same semaphore ID
used by some other task of priority 20 or temp. raising to priority 20.

When you changed the priorities of the tasks you could get 'some
progress'.Hence it must be the issue with priorities.This should get
resolved when you opt for binary semaphore.Make sure the semaphore IDs
are UNIQUE in the system.
Hope this was useful.

cheers-
kaushal.

.



Relevant Pages

  • Re: output.c error in multithreaded program
    ... >please see further below about a couple of semaphore questions). ... just modify your queue insertion routine to put the request in the ... scheduling priorities give you control over priority of how things are done). ... Why have an array of handles and an array of counts when the natural ...
    (microsoft.public.vc.mfc)
  • Re: Lahman, how ya doing?
    ... >> A priority queue is an interesting idea. ... So Timer just enqueues the event on the right queue. ... >effectively starts at the same time on the current tick. ... >was triggered just gets time-sliced based on priority. ...
    (comp.object)
  • Re: Lahman, how ya doing?
    ... Suppose you had 64 Thermometers and at run time you wanted to give priority to some of them dynamically (e.g., where the temperature gradient was greatest) because processing all 64 samples at once can't be done in a single "tick". ... So Timer just enqueues the event on the right queue. ... So I addressed both the bitmap processing basics via indexed OR mask and the deferredBitmap variable assumption about bit count. ...
    (comp.object)
  • Re: How to get synchronized efficiently
    ... A semaphore, behaving as a mutex, is one way to protect access to a queue. ... The choice of the best sync model ALWAYS depends on the design of your ... Let's set aside IOCP and consider the semaphore case. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: cooperative multitasking scheme
    ... >> equal priority or where priorities aren't specifically used. ... where I choose not to use preemption at ... the action of the timing event is to move the process from the sleep queue ... I very much appreciate having a sleep queue. ...
    (comp.arch.embedded)