[riot-notifications] [RIOT-OS/RIOT] sys/sema_inv: add inverse Semaphore (#15762)

Marian Buschsieweke notifications at github.com
Thu Jan 14 09:30:18 CET 2021


I wonder if this can be easily generalized in a way to allow implementing synchronization barriers. Something like `sema_inv_post_and_wait()`.

On the first look this seems like it would only require `mutex_unlock()` to be called in a loop until the mutex becomes free. But on a second look this looks like a race condition. If two low priority threads do make it to post, but haven't enqueued in the mutex yet, they will not be woken up by a third high priority thread doing the final post and unlocking the mutex. (Well, one of the two will obtain the mutex when it is free, but the other will block.)

One could solve above be enqueuing in the mutex first without yielding yet, posting afterwards, then yielding.

And if we would like to generalize a bit more to allow multiple threads to wait via `sema_inv_wait()`, above solution would again be racy: If all posts have been made prior to the calls to `sema_inv_wait()`, the second thread calling `sema_inv_wait()` to late would also block forever.

I think that implementing this on top of `core/cond` would allow for both generalizations - but would be a bit less lean.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15762#issuecomment-760017564
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210114/4f10c709/attachment.htm>


More information about the notifications mailing list