[CMake] CMake exclusive lock

David Cole david.cole at kitware.com
Mon Aug 2 08:06:49 EDT 2010


I can think of two ways to address a problem like this.

1) Serialize access to the "central file" by establishing dependencies among
all the writers to the central file. Make your nth call depend on n-1, n-1
on n-2, ... 3 on 2, 2 on 1. That forces the steps that access the file to
run serially and in order. May or may not be feasible for you. Might
completely ruin parallelization of the build of your project.

2) Create a bunch of "distributed files" and then after all distributed
files are written, run one more custom command to assemble the distributed
files into your central file.

Either way, it's probably a lot of work. Sorry I don't have an "easy" thing
for you to try...


:-)
David


On Mon, Aug 2, 2010 at 3:15 AM, Denis Scherbakov <denis_scherbakov at yahoo.com
> wrote:

> Hi! I have a project, where for some targets I have a POST_BUILD rule,
> which adds some data about this target into a "central file". If I build a
> project with several threads sometimes I get errors, when both threads try
> to write into this "central file" at the same time.
>
> So I was wondering, if there is some way of doing an exclusive
> lock/mutex/semaphore with CMake scripts?
>
> Maybe you have some other ideas how to correctly write into one file from
> different threads?
>
> Thanks! Denis
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100802/7513bb58/attachment.htm>


More information about the CMake mailing list