4 ms·
OK, I see. Your implementation sounds a little like how "make -j" is actually implemented (in C). This basically sounds like implementing a semaphore with a pi
by chubot 10y ago
OK, I see. Your implementation sounds a little like how "make -j" is actually implemented (in C).
This basically sounds like implementing a semaphore with a pipe.
http://make.mad-scientist.net/papers/jobserver-implementation/ http://make.mad-scientist.net/papers/jobserver-implementatio...
"""
Rather than using complex schemes such as a central server, shared memory, sockets, etc. for synchronizing the various instances of make, he suggested we use the simplest, most basic UNIX construct: a pipe. Not only is this easy, but it’s also a relatively portable concept. Most operating systems these days implement some sort of pipe feature, because that paradigm is so useful.
The idea is ingeniously simple: the initial, top-level make creates a pipe and writes N one-byte tokens into the pipe. That pipe is shared between that make and all submakes, and any time any make wants to run a job it first has to read a token from the pipe. Once the job is complete, it writes the token back to the pipe. Since there are only N tokens, you know that you will never invoke more than N jobs.
"""
- gpderetta 10y agoYes, except that gmake implementation is brilliant as it uses the pipe itself as a semaphore, while my version had an explicit process keeping a count and listening to V and P messages. Unfortunately I didn't know how make -j was implemented at that time.