TRT
Sign in

Advanced · Module 7 · Lesson 4 of 8

Read-Write Locks and Barrier Synchronization

Scale concurrent read workloads with pthread read-write locks, resolve reader/writer starvation policies, and synchronize parallel phases using pthread barriers.

Pro — members onlyAbout 16 minutes

By the end you can

  • Permit concurrent shared reads while enforcing exclusive writes using pthread_rwlock_t
  • Diagnose and prevent writer starvation using writer-preference lock attributes
  • Synchronize multi-threaded computation phases across threads using pthread_barrier_t
  • Identify the serial coordinating thread using the PTHREAD_BARRIER_SERIAL_THREAD return code

Builds on Condition Variables: pthread_cond_wait, Predicate Loops, and Spurious Wakeups.

01 · A question first

Why does replacing a standard mutex with a read-write lock sometimes make an application run slower instead of faster, while on read-heavy workloads it yields near-linear multi-core scaling? And how do parallel compute pipelines synchronize discrete step phases without spinning or joining threads?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Barrier Synchronization (pthread_barrier_t)
  • Why it is correct
  • What it costs
  • Pitfalls and variations
  • Where it is used

03 · Practice

Something wrong with this lesson? Report a problem