xtimer: check in xtimer_mutex_lock_timeout timeout callback if a thread blocked on mutex#11543
Conversation
Check case where xtimer_mutex_lock_timeout() does not time out. This will be used to show concurrency issue in further commit.
Prevent a possible race condition when _mutex_timeout fires just after the
mutex was locked but before the xtimer was removed
The flow
int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout) {
...
mutex_lock(mutex);
/* mutex locked */
/* _mutex_timeout fires and tries to remove thread from mutex queue */
/* DEBUG: simulate callback call between lock and remove */
xtimer_spin(xtimer_ticks_from_usec(timeout*2));
xtimer_remove(&t);
...
}
|
We updated the pull request from @pwillem with a test to show the assertion. The difference in the commit will be reverted when removing the throwaway commit. The fix is included in #11225 but the pull request does other things that do not all works. Better fix one thing at a time to simplify the review and documentation. |
|
I contributed to this pull request so cannot really review myself. The testing procedure gives the same result with |
| USEMODULE += xtimer | ||
| USEMODULE += shell | ||
|
|
||
| include $(RIOTBASE)/Makefile.include No newline at end of file |
There was a problem hiding this comment.
Missing new line at the end.
|
We noticed more issues as this change breaks the case where |
|
@JulianHolzwarth @cladmi thanks for taking care of this. I've not been very active on RIOT recently, but I'll try to take a look at this one and test ASAP. |
|
@vincent-d there are way more issues than this, and basically, what does not go in the normal timeout during |
|
I will close this pr.
|
The tracking pr: #11660
This pr is the same pr as #10872 with a test and edited commit message.
it also includes a throwaway test commit.
Contribution description
Prevent a possible race condition for xtimer_mutex_lock_timeout when _mutex_timeout fires just after the mutex was locked but before the xtimer was removed
The flow
Testing procedure
with the fix the test works,
without the fix
issues/PRs references
This is the same pr as #10872 with a test.
#11660: tracking pr for xtimer_mutex_lock_timeout function