dcbaker / meson-plus-plus

An experimental and incomplete implementation of Meson in C++, for solving Meson's bootstrapping issue.
Apache License 2.0
50 stars 7 forks source link

mir/passes/thread: Fix race condition in getting jobs #144

Closed dcbaker closed 2 weeks ago

dcbaker commented 2 weeks ago

The current code does if !empty; get_job(), Of course, it's possible for there to be one job left, and two threads race between the !empty check and the get() call.

Instead, we need to check the empty status with the lock held. The easiest way to handle this is to move the check into the get() call, and return an optional.