home | list info | list archive | date index | thread index

Re: possible race condition in makefile with multiple dependencies?

  • Subject: Re: possible race condition in makefile with multiple dependencies?
  • From: "Robert P. J. Day" <rpjday [ at ] crashcourse [ dot ] ca>
  • Date: Thu, 3 Jun 2021 11:55:38 -0400 (EDT)
On Thu, 3 Jun 2021, Dianne Skoll wrote:

> On Thu, 3 Jun 2021 10:19:22 -0400
> "Michael P. Soulier" <msoulier [ at ] digitaltorque [ dot ] ca> wrote:
>
> > On 2021-06-03 10:09 a.m., Dianne Skoll wrote:
> > > See the -j option
>
> > Seems like a race condition waiting to happen.
>
> Shouldn't be.  My understanding (which may be wrong) is that make
> calculates the dependency graph first, not in parallel.  Then it
> executes as many parallel tasks as the -j option asks for, or that
> make sense... whichever is smaller.  Since the dependency graph is a
> DAG, make should, in theory, be smart enough to see that two
> dependencies depend on the same node and run only one job to build
> the depended-upon node.
>
> I routinely use "make -j `nproc`" and have never run into any
> issues.

  reason i was asking is that, on current contract, devs were
complaining that a legacy makefile was taking ***forever*** to run, so
i took a look at it and it was a holdover from (i believe) QNX where
their version of make did not support parallelism so that many of the
rules were in the form:

target: dep1 dep2 dep3 dep4
	$(MAKE) -C subdir1
	$(MAKE) -C subdir2
	...
	$(MAKE) -C subdirn

and AFAIK, even under gnu make parallelism, the commands in any rule
are still run sequentially, so that the above would have to finish the
first make before going to the second, and so on. so i suggested that
refactoring the makefile to turn all those sub-makes into actual
dependencies would probably speed things up, given that the build
system is a 40-core beast.

rday

To unsubscribe send a blank message to linux+unsubscribe [ at ] linux-ottawa [ dot ] org
To get help send a blank message to linux+help [ at ] linux-ottawa [ dot ] org
To visit the archives: https://lists.linux-ottawa.org