[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
make -jN runs some rules more than once
From: |
Brian Malehorn |
Subject: |
make -jN runs some rules more than once |
Date: |
Thu, 10 Sep 2015 15:17:44 -0700 |
Consider the following Makefile:
all: a.gz b.gz
a.gz b.gz:
touch a
gzip a
touch b
gzip b
If you run it with 'make -j1', it runs fine.
But if you run it with 'make -j2',
- target "a.gz" must be built, spawning job 1 to build "a.gz b.gz"
- target "b.gz" must be built, spawning job 2 to build "a.gz b.gz"
- they trip over each other and the build crashes
There are plenty of workarounds, but this strikes me as a bizarre
default behavior. Shouldn't the rule "a.gz b.gz" should only be run once,
regardless of -jN?
This is how 'make -j2' should have gone:
- target "a.gz" must be built, spawning job 1 to build "a.gz b.gz"
- target "b.gz" must be built, but the rule to build it, "a.gz b.gz",
is already being executed. No job is spawned.
I ask because I just spent a few hours debugging a Makefile with the
false assumption that "a.gz b.gz" would only be run once. It's intuitive
that each each target should be built with a "task queue" rather than a
"parallel free-for-all", and I'm sure this design decision has lead to
pain for a lot of other programmers, too.
Thanks,
Brian
- make -jN runs some rules more than once,
Brian Malehorn <=