Skip to content

Instantly share code, notes, and snippets.

View hdonnay's full-sized avatar

Hank Donnay hdonnay

View GitHub Profile

UNIX famously uses fork+exec to create processes, a simple API that is nevertheless quite tricky to use correctly and that comes with a bunch of problems. The alternative, spawn, as used by VMS, Windows NT and recently POSIX, fixes many of these issues but it overly complex and makes it hard to add new features.

prepare() is a proposed API to simplify process creation. When calling prepare(), the current thread enters “preparation state.” That means, a nascent process is created and the current thread is moved to the context of this process, but without changing memory maps (this is similar to how vfork() works). Inside the nascent process, you can configure the environment as desired and then call prep_execve() to execute a new program. On success, prep_execve() leaves preparation state, moving the current thread back to the parent's process context and returns (!) the pid of the now grownup child. You can also use prep_exit() to abort the child without executing a new process, it similarly returns the pid

Do You Like DAGs?

Understanding Communicating Sequential Processes, (Directed) Acyclic Graphs, and the select Operator

After much discussion with Roger Peppe (@rogpeppe) following my speech at gophercon, I thought it might be best to clarify my thoughts on and understanding of how to avoid deadlocks in go (using CSP, DAG's and select).

Damian Gryski (@dgryski) provided a link to a nice summary of the conditions necessary for a deadlock:

  1. mutual exclusion
  2. hold and wait or partial allocation
  3. no pre-emption
  4. resource waiting or circular wait