larskanis/fxruby

Running two threaded apps

Closed this issue · 4 comments

When I try to run two apps in separate threads I get the following error:

in `initialize': attempted to create more than one FXApp instance (RuntimeError)

How is one supposed to run two apps at the same time? I understand that if one creates a global app and then adds all the desired windows to it that it will work. However, this is inconvenient because there may be certain actions that need to be taken after the app is created. There is also the question of how to add each "app's" windows in the first place, especially when you are require'ing them from different files. Is there an easy, clean way to do these things (e.g., an after-create hook)?

Equally to most other GUI frameworks, fxruby allows GUI interaction only from one thread. It is not safe to run different windows in different threads. Instead you should do CPU intensive or IO waiting tasks in separate threads and use runOnUiThread to make any GUI changes from these threads.

There is an example for GUI changes in a multithreaded application: https://github.com/larskanis/fxruby/blob/1.6/examples/thread.rb

"Instead you should do CPU intensive or IO waiting tasks in separate threads and use runOnUiThread to make any GUI changes from these threads."

ok, that's useful to know, although it doesn't really address this particular use case. I guess I'll just write a shell script then. Why is it unsafe to run windows in different threads?

I guess I'll just write a shell script then.

So you'll not using threads at all, but processes? That's safe.

Why is it unsafe to run windows in different threads?

Because neither fxruby, Xlib nor Win32 GDI are thread safe. You can use different processes, but should not use different threads for GUI calls.

Maybe I don't understand your issue. Could you provide some more information about your particular use case? What are you implementing?

Thanks for your response - I was able to find a workaround. It is probably an unusual use case, so don't worry about it.