How to make mutex support timeout?

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

How to make mutex support timeout?

Postby yenWu » Sun Oct 22, 2017 2:58 pm

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: 12458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 625 times
Been thanked: 527 times
Contact:

Re: How to make mutex support timeout?

Postby Giovanni » Sun Oct 22, 2017 4:12 pm

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: 130
Joined: Mon Sep 25, 2017 8:27 am
Has thanked: 8 times
Been thanked: 18 times
Contact:

Re: How to make mutex support timeout?

Postby tridge » Tue Jan 21, 2020 4:15 am

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.


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 2 guests