OCaml Forge
SCM

Detail: [#1038] Better implementation of Glib.Main.iteration

Patches: Browse | Download .csv | Monitor

[#1038] Better implementation of Glib.Main.iteration

Date:
2011-09-21 17:45
Priority:
3
State:
Open
Submitted by:
Jérémie Dimino (dim)
Assigned to:
Nobody (None)
Resolution:
Awaiting Response
Version:
None
Component:
None
 
Summary:
Better implementation of Glib.Main.iteration

Detailed description
Hi,

I recently wrote a program using lablgtk2 and threads and noticed that it never goes idle. After looking at the code it seems to be because the call to g_main_iteration is not done in a blocking section (because it may call ocaml functions) and so GtkThread cannot just call [Glib.Main.iteration true].

However it is possible to do separately the polling and the dispatching with glib, making it possible to do the blocking part (the polling) in a blocking section, and so to use GMain.main in multithreaded programs. The following patch does that.

Followup

Message
Date: 2012-08-17 12:58
Sender: Jérémie Dimino

Indeed, it seems much better this way. I'll try to do some testing this week end.
Date: 2012-08-17 11:44
Sender: Jacques Garrigue

Implemented this idea in the git repository, but used set_poll_func rather than reimplement.
Seems to work, but some testing would help.
Date: 2012-08-17 07:09
Sender: Jacques Garrigue

Sorry, this was a stupid comment.
Of course, if we have a blocking section, then ocaml threads are called by the ocaml scheduler as usual...
So the only question is whether this piece of code is stable enough that we can recode it ourselves.
This looks like a good candidate for inclusion.
Date: 2012-08-17 07:03
Sender: Jacques Garrigue

This looks like a nice approach, but how does it ensure that ocaml threads actually get called even when there are no Gtk events?

Attached Files:

Attachments:
0001-Reimplement-Glib.Main.iteration.patch

Changes:

Field Old Value Date By
ResolutionNone2012-08-17 07:03garrigue
File Added142: 0001-Reimplement-Glib.Main.iteration.patch2011-09-21 17:45dim