Hey guys,
Please ignore the quoted contents, I don't know why I can't receive the
thread emails but the Iup-users Digest.
Well when I read the source code of IupMainLoop() expecting some clue, I do
find a clue, iupdrvSetIdleFunction(). I guess it will be called inside
IupMainLoop() when it's idle so I put a test code in there, please find the
attached snippet.
In simple words, I moved all IUP related events into the idle function and
let it communicate with other thread via a global variable (just to prove
the concept, will be changed to a message queue later). It works pretty
well :-)
The only problem is this approach looks like a hacking. The
iupdrvSetIdleFunction() is an internal function which means it should not
be called by users. Another only problem will be the CPU usage could be
high because you have to poll your events/messages/etc constantly inside
the idle function. It's legal but nasty.
Hi John,
I'm afraid I don't understand script basic. Any idea in C?
Hi Milind,
I thought about the timer but haven't tried it yet. How's the performance?
Hi Ranier,
I think the main issue is not choosing which IPC but how to run IPC in the
main IUP thread. Currently I can't have the main IUP thread accepting
events from other threads.
Hi Jörg,
It sounds we are looking at the same problem, how to unblock the gui inside
main loop.
Hi Scuri,
Is there some method officially recommended by IUP team, similar to my
hacking in iupdrvSetIdleFunction(), to intercommunicating between threads?
For example, some function call to insert IUP events into underlay event
list so it will be processed finally in the main loop? In that case, I can
send notification in other threads and it will trigger an event in main IUP
thread so my codes could update the progress bar or something else?
Kind regards
Andy
On 6 October 2015 at 21:25, <iup-users-requ...@lists.sourceforge.net> wrote:
> Send Iup-users mailing list submissions to
> iup-users@lists.sourceforge.net
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.sourceforge.net/lists/listinfo/iup-users
> or, via email, send a message with subject or body 'help' to
> iup-users-requ...@lists.sourceforge.net
>
> You can reach the person managing the list at
> iup-users-ow...@lists.sourceforge.net
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Iup-users digest..."
>
>
> Today's Topics:
>
> 1. Re: Is Iup pthread safe? (John Spikowski)
> 2. Re: Is Iup pthread safe? (Ranier VF)
> 3. Re: Is Iup pthread safe? (Andy Xiyue)
> 4. Re: Is Iup pthread safe? (Milind Gupta)
> 5. Re: Is Iup pthread safe? (John Spikowski)
> 6. Re: Is Iup pthread safe? (Ranier VF)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 01 Oct 2015 23:39:24 -0700
> From: John Spikowski <supp...@scriptbasic.org>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: "IUP discussion list." <iup-users@lists.sourceforge.net>
> Message-ID: <1443767964.2357.2.camel@laptop>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi Andy,
>
> IUP isn't thread safe by default but that doesn't mean it can't be done.
> Here is an example in Script BASIC (Windows & Linux)
>
> http://www.scriptbasic.org/forum/index.php/topic,335.0.html
>
> John
>
>
> On Fri, 2015-10-02 at 14:36 +1000, Andy Xiyue wrote:
> > Hi Scuri,
> >
> >
> > Recently I tried to use IUP with more than one thread. My plan is
> > simple, run IupMainLoop() in one thread and feed progress bar or text
> > control in another thread. Theoretically I don't need to synchronize
> > the IUP calls because the IupMainLoop() will process the events sooner
> > or later. However I met a lot of problems. Sometimes the client area
> > became invalided without refresh. Sometimes I got a core dump
> > triggered by X11 event. For example, the attached file was simplified
> > from my program. When the progress bar running, if you select text in
> > the text control, the app will received sig 11:
> >
> > iqiup: Fatal IO error 11 (Resource temporarily unavailable) on X
> > server :0.0.
> >
> >
> > It looks like I misunderstood the programming model of IUP. Is IUP
> > safe to update the attribution of controls in different thread? If
> > it's not, how can I manually send events to the main loop to update
> > the controls?
> >
> >
> > Kind regards
> >
> > Andy
> >
> >
> ------------------------------------------------------------------------------
> > _______________________________________________
> > Iup-users mailing list
> > Iup-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 2 Oct 2015 10:03:13 +0000
> From: Ranier VF <ranier_...@hotmail.com>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: IUP discussion list. <iup-users@lists.sourceforge.net>
> Message-ID: <bay168-w110f48abdeb2d5e950b3b19e3...@phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,Neither GUI is thread safe.You need call Thread GUI, to update the
> interface.From: http://webserver2.tecgraf.puc-rio.br/iup/MultithreadUser
> interface is usually not thread safe and IUP is not thread safe. The
> general recommendation when you want more than one thread is to build the
> application and the user interface in the main thread, and create secondary
> threads that communicates with the main thread to update the interface. The
> secondary threads should not directly update the interface.
> Best,Ranier Vilela
>
> > From: supp...@scriptbasic.org
> > To: iup-users@lists.sourceforge.net
> > Date: Thu, 1 Oct 2015 23:39:24 -0700
> > Subject: Re: [Iup-users] Is Iup pthread safe?
> >
> > Hi Andy,
> >
> > IUP isn't thread safe by default but that doesn't mean it can't be done.
> > Here is an example in Script BASIC (Windows & Linux)
> >
> > http://www.scriptbasic.org/forum/index.php/topic,335.0.html
> >
> > John
> >
> >
> > On Fri, 2015-10-02 at 14:36 +1000, Andy Xiyue wrote:
> > > Hi Scuri,
> > >
> > >
> > > Recently I tried to use IUP with more than one thread. My plan is
> > > simple, run IupMainLoop() in one thread and feed progress bar or text
> > > control in another thread. Theoretically I don't need to synchronize
> > > the IUP calls because the IupMainLoop() will process the events sooner
> > > or later. However I met a lot of problems. Sometimes the client area
> > > became invalided without refresh. Sometimes I got a core dump
> > > triggered by X11 event. For example, the attached file was simplified
> > > from my program. When the progress bar running, if you select text in
> > > the text control, the app will received sig 11:
> > >
> > > iqiup: Fatal IO error 11 (Resource temporarily unavailable) on X
> > > server :0.0.
> > >
> > >
> > > It looks like I misunderstood the programming model of IUP. Is IUP
> > > safe to update the attribution of controls in different thread? If
> > > it's not, how can I manually send events to the main loop to update
> > > the controls?
> > >
> > >
> > > Kind regards
> > >
> > > Andy
> > >
> > >
> ------------------------------------------------------------------------------
> > > _______________________________________________
> > > Iup-users mailing list
> > > Iup-users@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/iup-users
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > _______________________________________________
> > Iup-users mailing list
> > Iup-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/iup-users
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> Message: 3
> Date: Tue, 6 Oct 2015 15:54:51 +1100
> From: Andy Xiyue <xiyue...@gmail.com>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: iup-users@lists.sourceforge.net
> Message-ID:
> <
> cafpcpfoggrkdhtvjjay5znapyt_ci+p-+wqnfjjqw393vsr...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Thanks John and Ranier.
>
> At least I'm confirmed now I can not update the attributions of IUP
> controls in other threads so my previous programming module was definitely
> wrong.
>
> So the question becomes how to send the control update event to the main
> thread?
>
> It's quite obvious the main thread is stuck in IupMainLoop(). Most events
> can be processed in this main thread, like buttons, text, etc. When users
> click the button, or inside the text input entry, the IUP generates the
> event and it will be processed in IupMainLoop(). However, how an external
> thread send the event into the main thread? I can't use message queue or
> semaphore because IupMainLoop() takes all the control. Are there some
> functions used for inserting IUP events?
>
> Kind regards
> Andy
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> Message: 4
> Date: Mon, 5 Oct 2015 22:01:48 -0700
> From: Milind Gupta <milind.gu...@gmail.com>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: "IUP discussion list." <iup-users@lists.sourceforge.net>
> Message-ID:
> <
> caojr7arwlukyrqrc5l1krbqj8ayon3iqoerurxcufrv86hx...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> What I did was to have a timer run and listen to communication from another
> thread. I used sockets to send and receive data.
>
> Milind
>
>
> On Mon, Oct 5, 2015 at 9:54 PM, Andy Xiyue <xiyue...@gmail.com> wrote:
>
> > Thanks John and Ranier.
> >
> > At least I'm confirmed now I can not update the attributions of IUP
> > controls in other threads so my previous programming module was
> definitely
> > wrong.
> >
> > So the question becomes how to send the control update event to the main
> > thread?
> >
> > It's quite obvious the main thread is stuck in IupMainLoop(). Most events
> > can be processed in this main thread, like buttons, text, etc. When users
> > click the button, or inside the text input entry, the IUP generates the
> > event and it will be processed in IupMainLoop(). However, how an external
> > thread send the event into the main thread? I can't use message queue or
> > semaphore because IupMainLoop() takes all the control. Are there some
> > functions used for inserting IUP events?
> >
> > Kind regards
> > Andy
> >
> >
> >
> ------------------------------------------------------------------------------
> >
> > _______________________________________________
> > Iup-users mailing list
> > Iup-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/iup-users
> >
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> Message: 5
> Date: Mon, 05 Oct 2015 22:17:15 -0700
> From: John Spikowski <supp...@scriptbasic.org>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: "IUP discussion list." <iup-users@lists.sourceforge.net>
> Message-ID: <1444108635.2309.11.camel@laptop>
> Content-Type: text/plain; charset="UTF-8"
>
> Andy,
>
> I feel if you follow what I have done in Script BASIC for threaded IUP
> it should work for you without any changes to anything.
>
> John
>
> On Tue, 2015-10-06 at 15:54 +1100, Andy Xiyue wrote:
> > Thanks John and Ranier.
> >
> >
> > At least I'm confirmed now I can not update the attributions of IUP
> > controls in other threads so my previous programming module was
> > definitely wrong.
> >
> > So the question becomes how to send the control update event to the
> > main thread?
> >
> >
> > It's quite obvious the main thread is stuck in IupMainLoop(). Most
> > events can be processed in this main thread, like buttons, text, etc.
> > When users click the button, or inside the text input entry, the IUP
> > generates the event and it will be processed in IupMainLoop().
> > However, how an external thread send the event into the main thread? I
> > can't use message queue or semaphore because IupMainLoop() takes all
> > the control. Are there some functions used for inserting IUP events?
> >
> >
> > Kind regards
> >
> > Andy
> >
> >
> ------------------------------------------------------------------------------
> > _______________________________________________
> > Iup-users mailing list
> > Iup-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Tue, 6 Oct 2015 10:25:10 +0000
> From: Ranier VF <ranier_...@hotmail.com>
> Subject: Re: [Iup-users] Is Iup pthread safe?
> To: IUP discussion list. <iup-users@lists.sourceforge.net>
> Message-ID: <bay168-w306d48c8bfe8ca829b9c65e3...@phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,Well, your implementation must be:one consumer (GUI thread)many
> producers (GUI events)
> You can use mutex-condition pair (classic), sockets or a new way pipes.
> Best,Ranier Vilela
>
> > From: supp...@scriptbasic.org
> > To: iup-users@lists.sourceforge.net
> > Date: Mon, 5 Oct 2015 22:17:15 -0700
> > Subject: Re: [Iup-users] Is Iup pthread safe?
> >
> > Andy,
> >
> > I feel if you follow what I have done in Script BASIC for threaded IUP
> > it should work for you without any changes to anything.
> >
> > John
> >
> > On Tue, 2015-10-06 at 15:54 +1100, Andy Xiyue wrote:
> > > Thanks John and Ranier.
> > >
> > >
> > > At least I'm confirmed now I can not update the attributions of IUP
> > > controls in other threads so my previous programming module was
> > > definitely wrong.
> > >
> > > So the question becomes how to send the control update event to the
> > > main thread?
> > >
> > >
> > > It's quite obvious the main thread is stuck in IupMainLoop(). Most
> > > events can be processed in this main thread, like buttons, text, etc.
> > > When users click the button, or inside the text input entry, the IUP
> > > generates the event and it will be processed in IupMainLoop().
> > > However, how an external thread send the event into the main thread? I
> > > can't use message queue or semaphore because IupMainLoop() takes all
> > > the control. Are there some functions used for inserting IUP events?
> > >
> > >
> > > Kind regards
> > >
> > > Andy
> > >
> > >
> ------------------------------------------------------------------------------
> > > _______________________________________________
> > > Iup-users mailing list
> > > Iup-users@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/iup-users
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > _______________________________________________
> > Iup-users mailing list
> > Iup-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/iup-users
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------
>
> _______________________________________________
> Iup-users mailing list
> Iup-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
> End of Iup-users Digest, Vol 77, Issue 2
> ****************************************
>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <pthread.h>
#include "iup.h"
Ihandle *dlg_main;
Ihandle *tune_label_total;
Ihandle *tune_label_fail;
Ihandle *tune_progress;
static int evt_update;
/* gcc -Wall -g -I./external/iup/include `pkg-config gtk+-2.0 --cflags` -L./external/iup/lib/Linux311_64 -o iqtuner iqiup.cpp -lpthread -liup `pkg-config gtk+-2.0 --libs` -lX11
*/
static int tuner_idle(void)
{
static int last_update;
static char buf[64], tune_fail[64];
if (evt_update != last_update) {
last_update = evt_update;
IupSetInt(tune_progress, "VALUE", evt_update);
sprintf(buf, "Frequency Tuned: %d", evt_update);
IupSetAttribute(tune_label_total, "VALUE", buf);
sprintf(tune_fail, "Failure of Tuning: %d", evt_update + 100);
IupSetAttribute(tune_label_fail, "TITLE", tune_fail);
}
return 1; /* must return TRUE */
}
static void *task_command(void *arg)
{
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
for (evt_update = 0; evt_update < 100; evt_update++) {
sleep(1);
}
return NULL;
}
int main(int argc, char **argv)
{
pthread_t task_cmd;
Ihandle *vbox_tune;
IupOpen(&argc, &argv);
IupSetGlobal("SINGLEINSTANCE", "IQTuner");
tune_label_total = IupText(NULL);
IupSetAttribute(tune_label_total, "READONLY", "YES");
IupSetAttribute(tune_label_total, "BORDER", "NO");
IupSetAttribute(tune_label_total, "BGCOLOR", "DLGBGCOLOR");
IupSetAttribute(tune_label_total, "CANFOCUS", "NO");
IupSetAttribute(tune_label_total, "SIZE", "120");
tune_label_fail = IupLabel(NULL);
IupSetAttribute(tune_label_fail, "TITLE", "Failure of Tuning: 0");
tune_progress = IupProgressBar();
IupSetAttribute(tune_progress, "EXPAND", "HORIZONTAL");
IupSetAttribute(tune_progress, "SIZE", "x10");
IupSetAttribute(tune_progress, "DASHED", "YES");
vbox_tune = IupVbox(tune_label_total, tune_label_fail, tune_progress, NULL);
IupSetAttribute(vbox_tune, "NGAP", "8");
IupSetAttribute(vbox_tune, "NMARGIN", "8x8");
dlg_main = IupDialog(vbox_tune);
IupSetAttribute(dlg_main, "TITLE", "IQTuner");
IupSetAttribute(dlg_main, "RASTERSIZE", "500x400");
IupShow(dlg_main);
IupSetInt(tune_progress, "MIN", 0);
IupSetInt(tune_progress, "MAX", 99);
iupdrvSetIdleFunction((Icallback)tuner_idle);
pthread_create(&task_cmd, NULL, task_command, NULL);
IupMainLoop();
pthread_cancel(task_cmd);
pthread_join(task_cmd, NULL);
IupDestroy(dlg_main);
IupClose();
return 0;
}
------------------------------------------------------------------------------
Full-scale, agent-less Infrastructure Monitoring from a single dashboard
Integrate with 40+ ManageEngine ITSM Solutions for complete visibility
Physical-Virtual-Cloud Infrastructure monitoring from one console
Real user monitoring with APM Insights and performance trend reports
Learn More http://pubads.g.doubleclick.net/gampad/clk?id=247754911&iu=/4140
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users