Race conditions multi threading

I have two threads running the idea is that i want my bluetooth thread to wake every 100ms and empty the serial buffer if needed. however when reading the values in the main thread the bits get all jumbled, when removing the thread and using as a function there are no issues the bytes come through perfectly so i am sure it is a race condition.

Is their anyway that i can stop another thread from interrupting the bluetooth thread if the buffer is not empty and the extern variable needs modifying?


Hi Jack,

In this scenario, you should consider using condition variable, it can handle this use case well.

1 Like