[9.18] Prefer the pthread_barrier implementation over uv_barrier
Prefer the pthread_barrier implementation on platforms where it is available over uv_barrier implementation. This also solves the problem with thread sanitizer builds on macOS that doesn't have pthread barrier.
(cherry picked from commit d07c4a98)
Backport of MR !7348 (merged)
Edited by Ondřej Surý