TcMenu / TaskManagerIO

A task, event, scheduling, and interrupt marshalling library for Arduino and mbed boards.
Apache License 2.0
124 stars 14 forks source link

Add support for a re-entrant lock that spin waits keeping other tasks running. #25

Closed davetcc closed 3 years ago

davetcc commented 3 years ago

One missing feature in task manager is the ability to handle reentrant locking within a task. For example, that means suppose we have a lock on I2C for example, that we lock in method A, and then method A then callls method B, which again locks I2C, which should succeed as it's locked by the same running task. However, a lock from any other task would have to spin wait by calling back into the task manager yield function.

This requires the currently running task to be exposed on the task manager object.

davetcc commented 3 years ago

Will be in the next release due shortly

davetcc commented 3 years ago

Needs more thought before putting it into the code base for the sake of compatibility. The biggest issue here is that if the yieldForMicros call is within a lock, and that also locks, then you have a classic deadlock. My immediate thoughts are to handle this by only supporting a tryLock instead of a full lock.

davetcc commented 3 years ago

Internally questioning if this is the right approach, certainly cannot be done as currently implemented.

davetcc commented 3 years ago

We've got this now, allowing task wide locks is working, and we've added an asynchronous mode too, so if the locks are in an observer -> observable pattern it can still work by making one side async.

davetcc commented 3 years ago

This is now in extended testing, releasing soon