This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Killing or suspending a task that waits for a lock?

I have an application with a worker thread and a controlling thread (amongst a lot of other threads). The worker is allowed to run for a certain amount of time, if it does not finish, it is first suspended (with TSK_setpri(worker, -1);) and the killed (TSK_delete(worker)) by the controller. The problem i am having seems to stem from a global lock, which is used for memory management. To ensure that the worker thread does not own the lock when it is suspended/killed, the controller thread acquires the lock before manipulating the worker. So far so simple, and working 99,9% of the time - but sometimes the app runs into some kind of deadlock.

After a lot of debugging, I have come to the conclusion that the following happens:

  1. thread xy acquires the global lock
  2. controller runs on LCK_pend(globak lock) and waits
  3. worker runs on LCK_pend(globak lock) and waits
  4. xy releases the lock
  5. controller acquires the lock
  6. controller suspends the the worker (setpri(-1))
  7. controller releases the lock
  8. worker acquires the lock
  9. -> deadlock, as the worker never continues

Finally my question:

  1. Is the above correct? Can a task with prio -1 acquire a lock?
  2. If so, is it ok to delete a task which currently waits on a LCK_pend? Or does this crash when the lock is freed?

Technical info: I am using DSP/BIOS 5.42.1.09 and CGT 7.0.3 on a C6000 device.

  • Hi Ruediger,

    what priorities are your worker and controller thread?

    Ruediger Casper said:
    Can a task with prio -1 acquire a lock?

    No. If you have set the worker's priority to -1, then that task is disabled and will not be run (so it can't get the lock).

    Ruediger Casper said:
    is it ok to delete a task which currently waits on a LCK_pend? Or does this crash when the lock is freed?

    The user's guide states that you need to carefully choose when to delete a task. That task must not have acquired a resource when it is deleted.

    Can you try your test without actually deleting the worker thread? When you reach your deadlock, it'd see if the worker task is disabled and if so, see if it has the global lock (or any other resource).

  • Tom Kopriva said:

    what priorities are your worker and controller thread?

    Worker 7, Controller 10

    Tom Kopriva said:

    No. If you have set the worker's priority to -1, then that task is disabled and will not be run (so it can't get the lock).

    It won't run, but as I see it, the lock is given to the pending tasks in the order in which they started to pend, regardless of their priority. So it gets the lock, but then won't run any further. Note that it started to pend while having priority 7.

    Ruediger Casper said:
    is it ok to delete a task which currently waits on a LCK_pend? Or does this crash when the lock is freed?

    I have since given it a try, and it is (seems to be?) working. I delete the worker while having acquired the lock in the controller - no more deadlock or crash now.