Week 4

Published

May 5, 2025

VL 7 - 05.05.25

posix state variables

  • pthread_cond_t, boolean variable cv.(it is actually a signalling / triggering variable)
  • posix state variables API: (Slide 11)
    • cond_wait(condition, mut)
    • cond_signal(condition)
    • cond_broadcast(condition): set condition to true, wake all sleeping
  • Flow of using cond vars (condition variables) (Slide 12 important):
    • (A)-event producer, (B)-event consumer
    • example: archive a data automatically (Slide 14 important)
  • Semaphores with active waiting - pseudocode. (semaphores require locks, locks require hardware solutions Klausurrelevant)
    • active waiting: infinite loop (ineffective). instead \(\Rightarrow\) sleeping.
  • semaphores toy implementation in C with structs without active waiting, rather with sleep, and block on the system level.

Synchronisation in Java

Slide: 29, …

  • keyword synchronized.
  • keywords wait() and notify().

Race conditions, synchronization, semaphores, locks, mutexes are all Klausurrelevant.

Interprocess Communication - IPC

  • Processes are in general independent and do not have an effect on each other. Nevertheless cooperation among processes is useful. How to achieve the cooperation between processes \(\Rightarrow\) IPC.
  • 2 main IPC families:
    • message passing - MP (safer)
    • shared-memory - SM (faster)

VL 8 - 07.05.25

IPC (cont.)

IPC has variouis APIs / Implementations

  • data streams: pipes, sockets, message queues, terminal, …
  • events
  • remote procedure call
  • shared memory

Message Passing

message passing can be blocking and non-blocking;

  • blocking = synchronous,
  • non-blocking = asynchronous.

Distributed IPC: communication between distinct computers

  • sockets: they imitate data systems
  • remote proecedure calls
  • web services:

Message Passing via Pipes

Anonymous pipes

instead of

ls -R >tmp-file.txt
grep -ci '\.jpg$' tmp-file.txt

we can do:

ls -R | grep -ci '\.jpg$' 
  • communication is realized by fork(): all the data etc is inherited by the child process.
  • closely related is: producer / consumer problem
Named Pipes

bi-directional communication

Data descriptors / handles

DD (file descriptor) is an integer (an index to a file data structure) and not a pointer.

There are standard DD values. Any time a process is started in Linux, three “files” are automatically opened that have the following DD values:

  • 0: stdin
  • 1: stdout
  • 2: stderr

These can be redirected in the shell. In order to achidve this the “hard-coded” DDs must “overwritten” \(\Rightarrow\) dup2():

int dup2(int srcDD, int targetDD)