I can think of two ways to address a problem like this.<div><br></div><div>1) Serialize access to the &quot;central file&quot; 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.</div>
<div><br></div><div>2) Create a bunch of &quot;distributed files&quot; and then after all distributed files are written, run one more custom command to assemble the distributed files into your central file.</div><div><br>
</div><div>Either way, it&#39;s probably a lot of work. Sorry I don&#39;t have an &quot;easy&quot; thing for you to try...</div><div><br></div><div><br></div><div>:-)</div><div>David</div><div><br></div><div><br><div class="gmail_quote">
On Mon, Aug 2, 2010 at 3:15 AM, Denis Scherbakov <span dir="ltr">&lt;<a href="mailto:denis_scherbakov@yahoo.com">denis_scherbakov@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi! I have a project, where for some targets I have a POST_BUILD rule, which adds some data about this target into a &quot;central file&quot;. If I build a project with several threads sometimes I get errors, when both threads try to write into this &quot;central file&quot; at the same time.<br>

<br>
So I was wondering, if there is some way of doing an exclusive lock/mutex/semaphore with CMake scripts?<br>
<br>
Maybe you have some other ideas how to correctly write into one file from different threads?<br>
<br>
Thanks! Denis<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>