Multiple threads

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple threads

Ernesto Rodriguez
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




_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
Reply | Threaded
Open this post in threaded view
|

Re: Multiple threads

Brandon Allbery

On Sat, Nov 21, 2015 at 4:59 PM, Ernesto Rodriguez <[hidden email]> wrote:
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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
Reply | Threaded
Open this post in threaded view
|

Re: Multiple threads

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?

Thanks

On Sat, Nov 21, 2015 at 10:07 PM, Brandon Allbery <[hidden email]> wrote:

On Sat, Nov 21, 2015 at 4:59 PM, Ernesto Rodriguez <[hidden email]> wrote:
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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net



--
Ernesto Rodriguez

Masters Student
Computer Science
Utrecht University




_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
Reply | Threaded
Open this post in threaded view
|

Re: Multiple threads

Brandon Allbery

On Sat, Nov 21, 2015 at 5:29 PM, Ernesto Rodriguez <[hidden email]> wrote:
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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
Reply | Threaded
Open this post in threaded view
|

Re: Multiple threads

Ernesto Rodriguez
Sounds like an interesting Sunday project :) Thank you for the advice!

On Sat, Nov 21, 2015 at 10:31 PM, Brandon Allbery <[hidden email]> wrote:

On Sat, Nov 21, 2015 at 5:29 PM, Ernesto Rodriguez <[hidden email]> wrote:
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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net



--
Ernesto Rodriguez

Masters Student
Computer Science
Utrecht University




_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad