← Back to the collection
SYSTEMS / 2021 / CONCURRENCY STUDY

Eleven threads. One molecule.

Making Propane

A synchronization exercise that coordinates eight hydrogen threads and three carbon threads to form propane.

MEDIUM
  • Java
BUILT WITH
  • Semaphores
  • Reusable barriers
ACCESS

Private source · project overview

01

Use chemistry to ask a systems question

Each atom is a thread. A molecule requires exactly three carbons and eight hydrogens, so a thread must wait until the right companions are available. Semaphores control access and separate queues coordinate the two atom types.

02

The harder part is reuse

The shared object owns an eleven-atom reusable barrier, but its calls are commented out in both atom threads. The barrier implementation also has counter and permit issues, and Carbon’s queue-release condition only checks the hydrogen count. A successful sample does not establish correctness across schedules. The diagram preserves those boundaries instead of presenting the intended design as verified behaviour.

SYSTEM SKETCH / CONCEPTUAL OVERVIEW
C C C ─────┐
           ├── rendezvous ──► C₃H₈
H H H H ───┤
H H H H ───┘
A reading of the architecture, not an application screenshot.
SYSTEM MAP / CLASS / SYNCHRONIZATION RELATIONSHIPS

Atom threads rendezvous through shared permits.

RunSimulation → Hydrogen extends Thread: start. RunSimulation → Carbon extends Thread: start. Hydrogen extends Thread → Propane: shared reference. Carbon extends Thread → Propane: shared reference. Propane → bond(atom): release queues → bond. Propane → BarrierReusable(11): owns; calls inactive.12345601 / ENTRY POINTRunSimulationCreate shared PropaneStart H and C threads02 / ATOMHydrogen extends ThreadIncrement H under mutexAcquire hydrogensQ → bond03 / ATOMCarbon extends ThreadIncrement C under mutexAcquire carbonQ → bond04 / SHARED OBJECTPropaneH / C counters · mutexhydrogensQ / carbonQ05 / OPERATIONbond(atom)Print bonding eventReset counts if H=8 and C=306 / DECLARED / INACTIVEBarrierReusable(11)phase1() / phase2()b_wait calls commented out
  1. 01 / entry point

    RunSimulation

    Create shared Propane

    Start H and C threads

    • start → 2. Hydrogen extends Thread
    • start → 3. Carbon extends Thread
  2. 02 / atom

    Hydrogen extends Thread

    Increment H under mutex

    Acquire hydrogensQ → bond

    • shared reference → 4. Propane
  3. 03 / atom

    Carbon extends Thread

    Increment C under mutex

    Acquire carbonQ → bond

    • shared reference → 4. Propane
  4. 04 / shared object

    Propane

    H / C counters · mutex

    hydrogensQ / carbonQ

    • release queues → bond → 5. bond(atom)
    • owns; calls inactive → 6. BarrierReusable(11)
  5. 05 / operation

    bond(atom)

    Print bonding event

    Reset counts if H=8 and C=3

    • 06 / declared / inactive

      BarrierReusable(11)

      phase1() / phase2()

      b_wait calls commented out

      1. 1RunSimulation Hydrogen extends Threadstart
      2. 2RunSimulation Carbon extends Threadstart
      3. 3Hydrogen extends Thread Propaneshared reference
      4. 4Carbon extends Thread Propaneshared reference
      5. 5Propane bond(atom)release queues → bond
      6. 6Propane BarrierReusable(11)owns; calls inactive
      This shows the checked-in code, including its limitations: barrier calls are commented out, and Carbon’s release condition only checks hydrogen count. The intended 8H + 3C rendezvous is not a proof of correct reuse.
      Read from the implementation
      • RunSimulation.java
      • Hydrogen.java / Carbon.java
      • Propane.java
      • BarrierReusable.java
      CONTINUE EXPLORING

      Virtual Memory →

      A command-line study of translating virtual addresses through a page table and writing their physical representations.

      2021
      • Java