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

possible race condition in makefile with multiple dependencies?

  • Subject: possible race condition in makefile with multiple dependencies?
  • From: "Robert P. J. Day" <rpjday [ at ] crashcourse [ dot ] ca>
  • Date: Thu, 3 Jun 2021 08:29:15 -0400 (EDT)
  i'm probably overthinking this, but is there any problem with
defining a makefile with numerous targets that can be processed in
parallel if they all have the same set of dependencies (which can also
be processed in parallel)?

  sample makefile i'm playing with:

.PHONY: all alldeps t1 t2 d1 d2

///// start

all: t1 t2
alldeps: d1 d2

d1:
        @echo "start d1"
        sleep 5
        @echo "end d1"

d2:
        @echo "start d2"
        sleep 5
        @echo "end d2"

t1: alldeps
        @echo "start t1"
        sleep 5
        @echo "end t1"

t2: alldeps
        @echo "start t2"
        sleep 5
        @echo "end t2"

///// end

  as you can see, if i run this makefile, it should process targets t1
and t2 in parallel, but since those targets both have dependencies of
"alldeps", the goal is that *all* dependencies (d1, d2) should be
processed and updated before *any* of the targets t1 or t2 are
allowed to proceed, but when they do, they can also be processed in
parallel.

  i *vaguely* recall (probably incorrectly) a possible race condition
in that both t1 and t2 will check their dependencies and, if they're
out of date, both try to update them at the same time, possibly
stepping on each other's work. i think that's unlikely, so am i
misremembering?

  in short, i will have a set of "dependencies" for a set of
"targets":

  * dependencies can be processed (updated) in parallel
  * targets can be processed (updated) in parallel
  * all dependencies must be up to date before any targets
    can start to be processed

is it this simple? or is there something i'm forgetting?

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