Discussion:
[xmonad] Multiple threads
Ernesto Rodriguez
2015-11-21 21:59:02 UTC
Permalink
Dear List,

Is it possible to render things in the XServer with multiple threads? For
example:

dpy <- asks display
myWin <- createSimpleWindow dpy (defaultRootWindow dpy) 0 0 10 10 black
white
_ <- forkOS $ do
-- doStuff with myWin using dpy

When I attempt doing things like that, I usually get a deadlock. Is there
any way to do this (I know, X is old :( but no harm in asking).

Thank you and best regards,

Ernesto Rodriguez
--
Ernesto Rodriguez

Masters Student
Computer Science
Utrecht University

www.netowork.me
github.com/netogallo
Brandon Allbery
2015-11-21 22:07:21 UTC
Permalink
Post by Ernesto Rodriguez
When I attempt doing things like that, I usually get a deadlock. Is there
any way to do this (I know, X is old :( but no harm in asking).
You can't, no, X11 is essentially incapable of it. (To the extent that
gtk2/3 has hacks to forward stuff to the main thread.)
Individual threads can open their own connections, a trick you'll see in
various contribs, but you can't share stuff between them; the best you
could do is send clientMessages from one thread to the other.

(X11 has a call to "enable" multithreading. This wraps a Big Global Lock
around all of X11. Even if you're using xcb, apparently, since if xcb could
do it properly gtk wouldn't go to such lengths to avoid it.)
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Ernesto Rodriguez
2015-11-21 22:29:28 UTC
Permalink
Oh well, thank you for the reply :) I am trying to do some networking stuff
in the X Monad. Do you think there is some workaround such that I do the
networking in an additional thread and then when it is done I fire some X11
event that XMonad can be programed to handle and then it can read the data
recovered from the network and display it?

Thanks
Post by Brandon Allbery
Post by Ernesto Rodriguez
When I attempt doing things like that, I usually get a deadlock. Is there
any way to do this (I know, X is old :( but no harm in asking).
You can't, no, X11 is essentially incapable of it. (To the extent that
gtk2/3 has hacks to forward stuff to the main thread.)
Individual threads can open their own connections, a trick you'll see in
various contribs, but you can't share stuff between them; the best you
could do is send clientMessages from one thread to the other.
(X11 has a call to "enable" multithreading. This wraps a Big Global Lock
around all of X11. Even if you're using xcb, apparently, since if xcb could
do it properly gtk wouldn't go to such lengths to avoid it.)
--
brandon s allbery kf8nh sine nomine associates
unix, openafs, kerberos, infrastructure, xmonad
http://sinenomine.net
--
Ernesto Rodriguez

Masters Student
Computer Science
Utrecht University

www.netowork.me
github.com/netogallo
Brandon Allbery
2015-11-21 22:31:32 UTC
Permalink
Post by Ernesto Rodriguez
Oh well, thank you for the reply :) I am trying to do some networking
stuff in the X Monad. Do you think there is some workaround such that I do
the networking in an additional thread and then when it is done I fire some
X11 event that XMonad can be programed to handle and then it can read the
data recovered from the network and display it?
That would be the ClientMessage I mentioned. You would have your thread
openDisplay for itself, do whatever, and then use sendMessage to send a
ClientMessage event to the main thread; you then use handleEventHook to
catch that event.
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Ernesto Rodriguez
2015-11-21 22:37:59 UTC
Permalink
Sounds like an interesting Sunday project :) Thank you for the advice!
Post by Brandon Allbery
Post by Ernesto Rodriguez
Oh well, thank you for the reply :) I am trying to do some networking
stuff in the X Monad. Do you think there is some workaround such that I do
the networking in an additional thread and then when it is done I fire some
X11 event that XMonad can be programed to handle and then it can read the
data recovered from the network and display it?
That would be the ClientMessage I mentioned. You would have your thread
openDisplay for itself, do whatever, and then use sendMessage to send a
ClientMessage event to the main thread; you then use handleEventHook to
catch that event.
--
brandon s allbery kf8nh sine nomine associates
unix, openafs, kerberos, infrastructure, xmonad
http://sinenomine.net
--
Ernesto Rodriguez

Masters Student
Computer Science
Utrecht University

www.netowork.me
github.com/netogallo
Loading...