Barrier-based synchronisation between threads