multithreading - How can I safely use WebKitGTK from a forked thread? -


I am trying to create a simple app in Haskell using GTK3 and WebKit. This code creates and displays a window containing a WebView inside, which displays a random number every time a key is pressed.

  import control. Monad Transaction import control. Concurrent (forkOS) import system. Random (random audio) import graphics. UI. Gtk - gtk3 Import Graphics.U.Getak Webkit Webview - WebKitgate's 3 main = forkOS $ do - Init GTK InitGUI - Create a window that will end the GTK loop - after closing Window & lt; --with the windowNew Window `` objectOstroy $ mainQuit - Create a WebView inside webview & lt; - WebWatching Set Window [Container Child: = Webview] - Make a random number of webvay displays on the key press. WebWeb `` On KeyWireVille $ lift $ do x & lt; - randomIO :: IO Int WebWoloadString Webview (Show X) Nothing "" Nothing "" Right Run GTK WidgetShowAll Window Chief  

When I run it in GHCi (7.8.3) So, it works fine. However, when I run it again without leaving GHCI, WebView never shows anything - just plain white area It's getting bothered, because I like to tinker with code in GHCI.

Of course, everything works fine if I do not use the forkOS and the whole thing runs in the main thread. What is the reason for this limitation (I thought that all GTK works are considered "main thread" in which initGUI is called ), and can it be overcome by any means?

If it works like a dragon (I'm not hacked), then you have to gtk main Loop should be placed in main thread .

Click on gtk . You should start your non-main thread before gtk main , so it has not been blocked.

I'm sure there is a compulsion for g_idle_add in Hackel G_timeout_add also works for that too.

The thread is not secure with gtk for doing all this.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -