orocos-toolchain / rtt

Orocos Real-Time Toolkit
http://www.orocos.org
Other
72 stars 79 forks source link

Fix race condition when waiting for functions #304

Closed meyerj closed 4 years ago

meyerj commented 5 years ago

Without the added lock of the message mutex it can happen that the calling thread wakes up and checks the completion condition in waitForMessagesInternal(), but the runner engine finishes and signals the condition variable in processFunctions() before the calling thread enters waiting state again.

This is a race condition and it is hard to catch it in a unit test.

This lock was already introduced in https://github.com/orocos-toolchain/rtt/commit/58cb4bb733fc14de0ca520620cfcb689e2155797 as part of #91, but has been reverted in https://github.com/orocos-toolchain/rtt/commit/b9f2f348959216f32819967d1b49910deeb4bed6 before the merge. There was a comment in https://github.com/psoetens/rtt/pull/3#issuecomment-280170267 that explains why the revert was needed, which also leaves the question open whether to keep the lock in processFunctions():

The interesting part is the comment in processMessages(). Maybe something similar was the case in processFunctions() and this is the only lock that was really required?