Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

Serialise for shared resources

Some tasks are best executed in series, either because they share resources which are more efficiently utilised in series or they share unique resources which cannot be accesed simultaniously.

A simple solution is to only invoke scons without -j N, unless N = 1.

In a build consisting of a mixture of tasks that can be executed in parallel and tasks that need to be serialised, requiring all the tasks that can be run in parallel to execute in series is non optimal.

The solution for the tasks that you know share resources is to tell scons that they create the same dummy file as a side effect. Scons will avoid executing only these tasks in parallel to avoid simultaneous acess to this dummy file.

Example

env.BuilderUsingSharedResource(source="x1.in",target="x1.out")
env.BuilderUsingSharedResource(source="x2.in",target="x2.out")
env.AnyOtherBuilder(source="x3.in",target="x3.out")

env.SideEffect("dummyfile","x1.out")
env.SideEffect("dummyfile","x2.out")

In this case when the script is invoked with scons -j 2 we should expect only x3.out to be created in parellel, the other two tasks should be completely serialised.

SerialiseForSharedResources (last edited 2013-12-20 10:41:50 by AlexBurton)