# How to avoid race for two \`cmake --build\` in parallel?

**URL:** https://discourse.cmake.org/t/how-to-avoid-race-for-two-cmake-build-in-parallel/9431
**Category:** Usage
**Created:** [November 15, 2023, 4:51am UTC](https://discourse.cmake.org/t/how-to-avoid-race-for-two-cmake-build-in-parallel/9431 "2023-11-15T04:51:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hehaoqian1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hehaoqian1/32/4007_2.png) [@hehaoqian1](https://discourse.cmake.org/u/hehaoqian1)
#### Post date: [November 15, 2023, 4:51am UTC](https://discourse.cmake.org/t/how-to-avoid-race-for-two-cmake-build-in-parallel/9431/1 "2023-11-15T04:51:37Z")

</div>

How to avoid race when two `cmake --build` are run in parallel, for the same cmake build directory?

For example, if I want to have `cmake --build . --target Alice` and `cmake --build . --target Bob` in parallel,  
and both of the targets depends on `Foo`.

How to ensure `Foo` is built only once without race?

Why I need to call two `cmake --build` in parallel?  
I need to call CMake from another build system, in order to specify dependency.

I am using Linux with ninja-build generator

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 19, 2023, 2:26am UTC](https://discourse.cmake.org/t/how-to-avoid-race-for-two-cmake-build-in-parallel/9431/2 "2023-11-19T02:26:06Z")

</div>

No, this is not supported. Though `ninja` might perform some locking making these effectively serial, there is no guarantee CMake provides itself.
