Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple threads copy file error on Windows #2402

Open
jiannanya opened this issue Mar 21, 2024 · 3 comments
Open

Multiple threads copy file error on Windows #2402

jiannanya opened this issue Mar 21, 2024 · 3 comments

Comments

@jiannanya
Copy link

Hi there.

When using cmake to add custom command to copy files like dlls to target output directory, since Ninja works with default multiple threads, the copy operation will fail after one thread has copy the same file.

When run ninja -j 1 then it will success.

My current operating system is Windows.

So is there anyway to work around it?

@digit-google
Copy link
Contributor

There is too little information here to answer you. E.g. what kind of failure are you talking exactly? Do you have a minimal reproduction case to share? So far, it looks like your CMake commands are running in parallel and lack the proper dependencies in your CMake declarations.

@jiannanya
Copy link
Author

There is too little information here to answer you. E.g. what kind of failure are you talking exactly? Do you have a minimal reproduction case to share? So far, it looks like your CMake commands are running in parallel and lack the proper dependencies in your CMake declarations.

For example, this line in the CMakeLists.txt https://github.com/JoeyDeVries/LearnOpenGL/blob/f2dc2e1904fe920ec52c734bd56888ab870ff937/CMakeLists.txt#L255

When copy file in parallel with Ninja build command, cmake will run into error due to multiple threads are coping the same file in the same time.

How to copy files in parallel with Ninja like such? I know the key is to add judgement when coping files, but I still want to know if Ninja has anything like atomic operation in c++?

@digit-google
Copy link
Contributor

This looks like a CMake-specific issue (e.g. you are using two PRE_BUILD add_custom_commands to write to the same location), not something related to Ninja itself. I recommend you ask on CMake-specific projects for help.

Ninja has multiple ways to ensure that commands only run in deterministic sequence when needed, here it looks like CMake didn't generate a Ninja build plan that used them properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants