Hi Andy,
         My timer runs ever 10ms and goes through a if-then block to parse
the commands received from the other thread. There are not many commands
something like 10 I think but I do pass tables with data with a command.
Since it is just user interface related I have not noticed any lag or any
hindrance or any hint of any slowdown. I haven't measured the performance
in any way except my user perception.

Milind




On Wed, Oct 7, 2015 at 2:15 AM, Andy Xiyue <xiyue...@gmail.com> wrote:

> 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
>> ****************************************
>>
>
>
>
> ------------------------------------------------------------------------------
> 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
>
>
------------------------------------------------------------------------------
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

Reply via email to