πŸ“— -> 02/06/26: ECS150-L13


makefile
Sync

🎀 Vocab

❗ Unit and Larger Context

Discussion: Makefile
Lecture: Synchronization

βœ’οΈ -> Scratch Notes

Synchronization

Using threads recap:

  • Private process registers
  • Private stack
  • Shared global memory

Can be independent (distinct areas of data [:N/2] and [N/2:] for instance) or cooperative (doing seperate things but both writing to a[i])

Concurrency issues:

Thread (preemptive) scheduling:

  • Indeterministic scheduling (many possible executions of thread orders)
    • Does the order of scheduling affect your program output? very important

Even good code can go bad:

Instruction reordering:

  • The compiler can reorder instructions (it assumes synchronous code?)
  • Hardware can reorder instruction (x86 is an out of order processor for instance)

Multi-word operations:

  • Not an atomic operation, gets decomposed into multiple lines by compiler (x=x+1 turns from a 3 instruction command into a 7 instruction command if int64 instead of normal int)
    • Makes the code even more vulnerable to interrupts

These issues all have a name: race conditions

Race conditions

Def: When the order of operations between concurrent threads leads to undesirable/unexpected results

Concurrency introduces different β€˜interleavings’ of code. MANY possible.

  • Most are good
  • Some may be very bad

Solution?

  • Synchronization

Use locks (basically):

# thread1
note1 = 1; 
while (note2 == 1) ; 
if (milk == 0) { milk++; }
note1 = 0;

# thread 2
note2 = 1;
if (note1 == 0) { 
	if (milk == 0) { milk++; } 
} 
note2 = 0;

Safe, but involved busy waiting

Peterson’s Algorithm

  • Share a single resource using only shared memory
  • Symmetric and scalable
  • complex
  • wiki

πŸ§ͺ -> Refresh the Info

Did you generally find the overall content understandable or compelling or relevant or not, and why, or which aspects of the content were most novel or challenging for you and which aspects were most familiar or straightforward?)

Did a specific aspect of the content raise questions for you or relate to other ideas and findings you’ve encountered, or are there other related issues you wish had been covered?)

Resources

  • Put useful links here

Connections

  • Link all related words