I think one desirable characteristic of XGB is thread safety. It allows for
truly parallel tasks that both perform X actions.
One example use is in my window manager. When I manage a new client, there are
a few images that need to be converted to pixmaps. It's an ideal task to
background. With thread safety in XGB, I can now do something like this and be
reasonably confident things will be ok:
manage(client) {
go func() {
// generate some images; they may be large!
}
// do non-cpu intensive stuff to manage client
}
Obviously, there are tons of other places where this might be useful---but I
think stuff related to image manipulation/painting are the most likely
candidates.
My approach to thread safety was to encapsulate replies in goroutines. This
seemed like the most obvious approach (to one who is inexperienced with
goroutines and channel usage), but incurs the overhead of channels and
goroutines every time a request requires a reply. However, I've been told that
goroutines are quite cheap :-)
I haven't done much testing yet, but it has survived some non-trivial stress
testing with my window manager.
I'm still not completely happy with everything, but comments and criticisms are
welcome.
My threadsafe branch is here:
http://code.google.com/r/jamslam-x-go-binding/source/browse/?name=threadsafe#hg%
2Fxgb
Original issue reported on code.google.com by jamslam@gmail.com on 15 Apr 2012 at 8:04
Original issue reported on code.google.com by
jamslam@gmail.com
on 15 Apr 2012 at 8:04