<html><head></head><body><div>On Fri, 2016-12-02 at 12:58 -0200, Till Kamppeter wrote:</div><blockquote type="cite"><pre>The solution would be to acquire a lock when starting to manipulate the
printer list and releasing the lock when done.
Now my qestion is, which functions I have to use for acquiring and
releasing locks when using GLib and GMainLoop? Probably it is not
correct to use the locks of pthread. Also it is probably best to use
Read/Write locks where only writing is exclusive but reading is allowed
to more than one thread at a time.
</pre></blockquote><div><br></div><div>Generally speaking the best way to do this is to use the mainloop itself as the lock. The mainloop is always on a single thread, so you should have the other threads put events into the main loop context and have them operate there on the data structure. So you'd, for instance, get all the information together on your Bonjour thread and when you're ready to add it put an action on the main loop with all that information.</div><div><br></div><div>The functions you're probably looking for are (as starting points):</div><div><br></div><div>g_main_context_get_thread_default()</div><div>g_idle_source_new()</div><div>g_source_attach()</div><div><br></div><div>Good luck!</div><div>Ted</div><div><br></div></body></html>