diff --git a/test/threads/hb-shape-threads.cc b/test/threads/hb-shape-threads.cc index fc0286d16..270ad582b 100644 --- a/test/threads/hb-shape-threads.cc +++ b/test/threads/hb-shape-threads.cc @@ -1,5 +1,6 @@ #include #include +#include #include #ifdef HAVE_CONFIG_H @@ -59,6 +60,11 @@ unsigned num_tests = sizeof (default_tests) / sizeof (default_tests[0]); enum backend_t { HARFBUZZ, FREETYPE }; +// https://en.cppreference.com/w/cpp/thread/condition_variable/wait +std::condition_variable cv; +std::mutex cv_m; +static bool ready = false; + static unsigned num_repetitions = 4; static unsigned num_threads = 4; @@ -66,6 +72,12 @@ static void shape (bool is_var, backend_t backend, const test_input_t &input) { + // Wait till all threads are ready. + { + std::unique_lock lk (cv_m); + cv.wait(lk, [] {return ready;}); + } + hb_font_t *font; { hb_blob_t *blob = hb_blob_create_from_file_or_fail (input.font_path); @@ -148,6 +160,9 @@ static void test_backend (backend_t backend, for (unsigned i = 0; i < num_threads; i++) threads.push_back (std::thread (shape, variable, backend, test_input)); + ready = true; + cv.notify_all(); + for (unsigned i = 0; i < num_threads; i++) threads[i].join (); }