Last Warning

Last Warning (1)

Multithreading does not go together well with fork()

  • fork() copies the address space ⟶ locked mutexes

  • fork() leaves only the calling thread alive in the child

    • All others are gone

  • If you have to use pthread_atfork() you’re lost

  • exec() is ok - everything’s gone anyway.

    • But why the hell would one do this?

  • Signals are not ok at all

Last Warning (2)

Multithreading is dangerous!

  • It is sexy

  • It is easy - a thread is created in no time (gosh: C++11)

  • There are race conditions everywhere

  • Keep hands off cancellation

  • Careful when sharing data structures ⟶ global variables aren’t bad for no reason

  • Debugging is nearly impossible

Last Warning (3)

man pthreads: legalese that deserves reading

  • “Thread-safe functions”: please please read!

  • “Async-cancel-safe functions” ⟶ don’t use cancellation