Hi Antonio,
I have been thinking about ipc, implemented as a (blocking) worker thread and 
how to communicate 
with the main GUI thread when a message is received. I found the 2008/12 thread 
with IupAsync and
had a look at how that was implemented... and then I started looking intently 
at WM_COPYDATA...
which I managed to convince myself would be a pretty good windows-only 
solution... and then I
started looking at the mentioned g_idle_add, and realised how non-thread-safe 
it would be to try
and get to that via IupSetFunction (because of the 
iupTableRemove()/iupTableSetFunc()) and then
finally I looked at iupdrvSetIdleFunction() in both iupgtk_loop.c and 
iupwin_loop.c

It appears that the calls to iupdrvSetIdleFunction() are thread safe*. I can 
see that quite clearly 
in iupwin_loop.c but I'm not at all familiar with g_idle_add etc as used in 
iupgtk_loop.c (ditto
XtRemoveWorkProc/XtAppAddWorkProc in iupmot_loop.c), and judging from the way 
those xxx_idle_cb 
are casually set to NULL in said files, would hazard table updates may not be 
necessary anyway?

Lastly I realised that if you had to go via idle_cb on Linux, but WM_COPYDATA 
on Windows, then 
best programming practice would be "invoke idle_cb from COPYDATA_CB", so why 
not go direct?

After all that, it seems we just need to export iupdrvSetIdleFunction() as 
IupSetIdleFunction()?

Three other quick points: I think it would be fair to say it is the 
programmer's responsibility 
to put any message somewhere idle_cb can find it, thread-safely (and nothing to 
do with IUP). 
It may also be the case that idle_cb exiting and nullifying xxx_idle_cb may 
overlap with another 
thread setting it, and again it would be reasonable to require the programmer 
to start a timer 
on exit from idle_cb to re-check things (once) say 0.5s later (also nothing to 
do with IUP).
*By thread safe I meant as in two threads setting a static int. They may 
over-clobber such that
a reader never gets to see both, but otherwise nothing catastrophic should 
happen. In this case
I am thinking two threads simultaneously setting a static var with the same 
value anyway.

Update: a quick google suggests g_idle_add and XtAppAddWorkProc are possibly 
thread safe.
As usual, however, the deeper I dig the less clear things become.
I'll just add a couple of references, which may or may not be relevant: 
https://mail.gnome.org/archives/gtk-devel-list/2007-November/msg00125.html
https://developer.gimp.org/api/2.0/gdk/gdk-Threads.html

Pete

------------------------------------------------------------------------------
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to