How to make mutex support timeout?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
yenWu
Posts: 1
Joined: Sun Oct 22, 2017 2:37 pm
Has thanked: 1 time

How to make mutex support timeout?

Post by yenWu »

Hello,

I'm hacking ChibiOS with mutex synchronization mechanism and testing demo code in `demo/RT-Posix-simulator`. It's amazing that mutex support PIP and recursive token in such code base.

However, There is a little weird about why mutex in ChibiOS/RT doesn't support timeout? I found that semaphore and condition variable support timeout. If I want to do something like `pthread_mutex_timeoutlock()`, is it possible?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to make mutex support timeout?

Post by Giovanni »

Hi,

It would be possible to add timeout to mutexes but it would be computationally complex because PIP, on timeout the thread would have to "recall" the priority boost that it gave to the thread(s) holding the mutex.

This is why it is not implemented, unlike all other mechanisms.

Without this "priority un-boost" thing it would be easy to add but the behavior would not be correct.

Giovanni
tridge
Posts: 141
Joined: Mon Sep 25, 2017 8:27 am
Has thanked: 10 times
Been thanked: 20 times

Re: How to make mutex support timeout?

Post by tridge »

If anyone has implemented mutex with timeout and priority inheritance then please let me know. It would be very useful for ArduPilot. As giovanni said, it does look quite complex to implement, but would be a really nice feature.
Post Reply