Reputation: 18264
Note that I am using Python but this could apply to any other bindings from glib.
I have a class that sets up several sockets connections via glib.io_add_watch()
and a callback method called foo()
. In addition, I have a glib.idle_add()
callback to a method called bar()
. foo()
creates or update a list (class member) of elements that can be any value including None. bar()
removes any None item form the above list -- we done with those, we no longer care. In effect it cleans things up.
Does glib grantee that only one callback will be called at any one time per thread?
If I were to run this code so that foo()
is in thread one and bar()
in thread two, there would be a race condition. I assume that a simple mutex would solve this but is there a more efficient way to do this?
Upvotes: 3
Views: 936
Reputation: 17492
Callbacks added via g_io_add_watch
and g_add_idle
are executed in the main loop's thread regardless of what thread they were added from.
Upvotes: 5