<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Friday 26. June 2009 21.08.55 Dmitry Kazakov wrote:<br>
&gt; I don&#39;t really know  how to solve it yet, but i  guess, we should make<br>
&gt; some &quot;locking  rules&quot;, and follow them...  This is the  only method of<br>
&gt; getting rid of deadlocks i know.  At least linux kernel uses it and it<br>
&gt; works [1].<br>
[]<br>
&gt; If you have some comments or suggestions - YOU ARE WELCOME! :)<br>
<br>
Lock free programming in Qt is possible using the QAtomic set of classes in<br>
Qt. QAtomicInt api docs; <a href="http://doc.qtsoftware.com/latest/qatomicint.html" target="_blank">http://doc.qtsoftware.com/latest/qatomicint.html</a><br>
This will give a nice read;<br>
<a href="http://labs.trolltech.com/blogs/2008/10/22/a-never-ending-struggle/" target="_blank">http://labs.trolltech.com/blogs/2008/10/22/a-never-ending-struggle/</a><br>
</blockquote></div><br>Thanks! A really nice read! :)<br>He seems to have introduced what is called &quot;Seqlocks&quot; in linux kernel since 2.5.<br>Speaking truly, i can&#39;t really see how to adopt it to tiles, as a tile can&#39;t be read atomically in one &quot;lock readq ...&quot; instruction.<br>
<br>We need to serialize access to the same tile from two different threads. COW can&#39;t help us in this situation (only one tile). The only lockless way of serialization i see here, this is Read-Copy-Update (RCU) method of linux kernel. It&#39;d be built on top of QAtomic, but it would introduce tooooo muuuch overhead in our situation as tiles are quite huge (4KiB)<br>
<br>The reason why  <a href="http://labs.trolltech.com/blogs/author/brad/">Bradley T. Hughes</a> succeeded with seqlocks his write-access code was encapsulated inside a small function. In Krita case, we write into tiles all over the code, and this very code hasn&#39;t been written in assuming that just having been read piece of data is broken and have to be reread again.<br>
<br>---<br>[1] <a href="http://en.wikipedia.org/wiki/Seqlock">http://en.wikipedia.org/wiki/Seqlock</a><br>[2] <a href="http://en.wikipedia.org/wiki/Read-copy-update">http://en.wikipedia.org/wiki/Read-copy-update</a><br clear="all">
<br>-- <br>Dmitry Kazakov<br>