Hi<br><br>Thanks for your answer.<br><br>My idea with the threads was to experiment. After browsing the QT API (of which I am no expert at all), I suppose that what I want to do would take great advantage of signals.<br>The way I see it:  Some QTcpSocket would send a signal when data is received, another helper class would handle this data, and emit another signal when a new track data is available. This signal would finally be used to update the QgsMapCanvasItem data in QGis. This seems cool.<br>
<br>I understand very well your remarks about the synchronization. However, since I am adding the items to the MapCanvas using the QGis API, and since this API doesn&#39;t seem to provide any way to synchronize the access to the items, I don&#39;t see how I could have the synchronization properly implemented. I can add all the mutexes that I want in my code, the QGis API won&#39;t synchronize...<br>
<br>Did I miss something? Is there an implicit synchronization in the Qt API regarding the QGraphicScene? <br><br>Thanks for your help again.<br>Florian<br><br><br><div class="gmail_quote">On Wed, Apr 29, 2009 at 11:28 AM, Martin Dobias <span dir="ltr">&lt;<a href="http://wonder.sk">wonder.sk</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Sat, Apr 25, 2009 at 11:38 AM, Florian El Ahdab &lt;<a href="mailto:felahdab@gmail.com">felahdab@gmail.com</a>&gt; wrote:<br>

&gt; [...]<br>
<div class="im">&gt;<br>
&gt; Here is my problem:<br>
&gt; When I create 1 of those items, everything works fine. With a map loaded, I<br>
&gt; can see the Item moving around every 500ms.<br>
&gt; But when I create 10 of those items (and consequently 10 threads), I can see<br>
&gt; them moving but qgis crashes randomly (between 1 and 10 seconds max).<br>
&gt; I suspect this is because there is no synchronization in the access to the<br>
&gt; Item data when the thread moves the item.<br>
&gt; I have tried to freeze the MapCanvas before updating the position... but it<br>
&gt; doesn&#39;t work either.<br>
&gt;<br>
&gt; Wonder:<br>
&gt; If my explanations are clear enough, can you help me?<br>
&gt; Can you detail a little bit further how you would do such a thing for a<br>
&gt; large amount of tracks (let&#39;s say 5000...).<br>
<br>
</div>Is it really necessary to use threads here? Usually much simpler<br>
approach is to use a timer that updates the items once in a while. And<br>
you don&#39;t have to worry about large number of threads and<br>
synchronisation.<br>
<div class="im"><br>
&gt; If there is a need for synchronization, how can I synchronize the access to<br>
&gt; the items that I have to add to the MapCanvas (which doesn&#39;t synchronize<br>
&gt; before using the data apparently.)<br>
<br>
</div>Yes, you have to synchronize the threads, otherwise you&#39;ll have<br>
concurrency problems. Everything shared among threads must be accessed<br>
safely, i.e. using mutexes, semaphores, r/w locks etc...<br>
<font color="#888888"><br>
Martin<br>
</font></blockquote></div><br>