cups-browsed uses GMainLoop and global variables, how to introduce locks against race conditions?

Ted Gould ted at
Fri Dec 2 16:28:02 UTC 2016

On Fri, 2016-12-02 at 12:58 -0200, Till Kamppeter wrote:
> 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.
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
The functions you're probably looking for are (as starting points):
Good luck!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the ubuntu-devel mailing list