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:
- thread xy acquires the global lock
- controller runs on LCK_pend(globak lock) and waits
- worker runs on LCK_pend(globak lock) and waits
- xy releases the lock
- controller acquires the lock
- controller suspends the the worker (setpri(-1))
- controller releases the lock
- worker acquires the lock
- -> deadlock, as the worker never continues
Finally my question:
- Is the above correct? Can a task with prio -1 acquire a lock?
- 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.