comp.lang.ada
 help / color / mirror / Atom feed
* multithreading with gtkada
@ 2002-11-14 16:59 evangeli
  2002-11-14 17:59 ` Warren W. Gay VE3WWG
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: evangeli @ 2002-11-14 16:59 UTC (permalink / raw)


hi all

it seems that gtk doesnt support multi-threading (see 
http://www.faqs.org/faqs/x-faq/part7/section-15.html).
My problem is the following :
my app opens a windows, which on the show event launch a task wich makes 
a long computation. The window also contains a cancel button which can 
be pressed to abort this task.The problem is that i would like this task 
to make X-Call, and that is apparently not possible and give me 
unavoidably the following error message:
----------------------------------------------
Xlib: unexpected async reply (sequence 0x9fe)!
----------------------------------------------
i havent found any solution which doesn't use several tasks.

1) Am i clear?
2) Do u have any idea of a different way to do that?
3) why this cruel destiny?

thanks for any response




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-14 16:59 multithreading with gtkada evangeli
@ 2002-11-14 17:59 ` Warren W. Gay VE3WWG
  2002-11-15 16:25   ` evangeli
  2002-11-14 18:41 ` David Marceau
  2002-11-14 22:00 ` Preben Randhol
  2 siblings, 1 reply; 7+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-11-14 17:59 UTC (permalink / raw)


evangeli wrote:
> hi all
> 
> it seems that gtk doesnt support multi-threading (see 
> http://www.faqs.org/faqs/x-faq/part7/section-15.html).

I believe that Gtk does support tasks, but on UNIX platforms,
Gtk will make use of the Xlib (as the ref above shows). This
library I believe is now thread safe on _some_ platforms,
but most certainly NOT on all of them.  I would certainly
not depend upon it for portable code.

> My problem is the following :
> my app opens a windows, which on the show event launch a task wich makes 
> a long computation. The window also contains a cancel button which can 
> be pressed to abort this task.The problem is that i would like this task 
> to make X-Call, and that is apparently not possible and give me 
> unavoidably the following error message:
> ----------------------------------------------
> Xlib: unexpected async reply (sequence 0x9fe)!
> ----------------------------------------------
> i havent found any solution which doesn't use several tasks.
> 
> 1) Am i clear?
> 2) Do u have any idea of a different way to do that?
> 3) why this cruel destiny?
> 
> thanks for any response

Your problem requires some careful Ada programming. You will need
to segment your application so that one or the following
approaches are used:

  - Only one task does Gtk (GUI) operations

or

  - You use an Ada technique to make certain that only one Ada task
    is doing a Gtk operation at any given instance (protected objects
    perhaps).

Sounds like you need the second approach. You can run into the same
situations when trying to use curses (text mode screens).

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-14 16:59 multithreading with gtkada evangeli
  2002-11-14 17:59 ` Warren W. Gay VE3WWG
@ 2002-11-14 18:41 ` David Marceau
  2002-11-14 22:00 ` Preben Randhol
  2 siblings, 0 replies; 7+ messages in thread
From: David Marceau @ 2002-11-14 18:41 UTC (permalink / raw)


evangeli wrote:
> 
> hi all
> 
> it seems that gtk doesnt support multi-threading (see
> http://www.faqs.org/faqs/x-faq/part7/section-15.html).
> My problem is the following :
> my app opens a windows, which on the show event launch a task wich makes
> a long computation. The window also contains a cancel button which can
> be pressed to abort this task.The problem is that i would like this task
> to make X-Call, and that is apparently not possible and give me
You clearly are in the cancel button callback function which means your
gtkhandle is busy already. 
Ok you try to call another Xwindow/gtk api service when it's already
busy(you are already in a gtk/xwindow callback for the
buttoncancelevent)
You are also hinting you're doing time-consuming-work within your
gtk-input-window-callback.  I'll get to why you shouldn't be doing this
later.

> unavoidably the following error message:
> ----------------------------------------------
> Xlib: unexpected async reply (sequence 0x9fe)!
> ----------------------------------------------
> i havent found any solution which doesn't use several tasks.
> 
> 1) Am i clear?
> 2) Do u have any idea of a different way to do that?
> 3) why this cruel destiny?
> 
> thanks for any response
Veering away from your problem for a moment, what exactly are you trying
to achieve with your gui without talking directly about ada?
If your intention is something like a progress bar with a cancel button,
have you looked at the demos that came with gtkada?
Essentially in the gtkada demos there is at least one demo that has a
main window which brings up a child progress window with a cancel
button.

Keeping in mind I haven't looked at gtkada recently(although I do like
it), here are the important concepts IMHO:
-I would suggest making your pseudo-progress-window modal because I
recommend you have only one window accepting input from the user at a
time(i.e. with focus and enabled).  Technically every different
gui-control either button/listbox/... is a window but I'm talking about
windows with usually a frame and decorations(i.e.
min/max/close/command-button/resize-edges).  Also known as FrameWindows
or MainWindows or ParentWidgets.  BTW Feel free to correct me if I'm
wrong :)  
-Once you follow that rule then keeping one global gtk handle and
protecting it(protected type) should be enough for you to draw and
update whenever you want from any task.  
-In that manner if a second or Nth task wants to draw, it will wait
until the-busy-drawing-task has unblocked the protected gtk handle.
-You will find more difficulty when dealing with user x input callbacks
from two or more ada tasks coming from two or more different windows. 
What you really want to avoid doing is being in a state where two
buttons in two different windows are pressed simultaneously or even the
same button in one window is pressed very quickly more than once.  This
is hard to do mind you but if you're ada time-consuming-work is actually
called from within the gui callback, you will suffer the consequences. 
Take the gui state, get out of the callback and let another task handle
the state and do the time-consuming-work.  This will avoid
gui-blocking/gui-deadlock and improve gui-responsiveness.  i.e. if you
press some compute button really quick more than once and your
application crumbles to a dead halt, you probably didn't separate the
concerns enough.
-whatever happens don't be afraid of trying stuff because the operating
system won't die.  You might have to re-startx or
win32-logout/win32-login though.  Saving your files before crapping out
your xserver or win32 session is always a good idea :)

I hope this gives you a bit of perspective.  Good luck. 

Sant� bonheur,
David Marceau



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-14 16:59 multithreading with gtkada evangeli
  2002-11-14 17:59 ` Warren W. Gay VE3WWG
  2002-11-14 18:41 ` David Marceau
@ 2002-11-14 22:00 ` Preben Randhol
  2 siblings, 0 replies; 7+ messages in thread
From: Preben Randhol @ 2002-11-14 22:00 UTC (permalink / raw)


evangeli wrote:
> hi all
> 
> it seems that gtk doesnt support multi-threading (see 
> http://www.faqs.org/faqs/x-faq/part7/section-15.html).
> My problem is the following :
> my app opens a windows, which on the show event launch a task wich makes 
> a long computation. The window also contains a cancel button which can 
> be pressed to abort this task.The problem is that i would like this task 
> to make X-Call, and that is apparently not possible and give me 
> unavoidably the following error message:
> ----------------------------------------------
> Xlib: unexpected async reply (sequence 0x9fe)!
> ----------------------------------------------
> i havent found any solution which doesn't use several tasks.

I got similar problems with my small toy application. You can see how I
did it. Perhaps it works for you:

   URL  =>  http://www.pvv.org/~randhol/Ada95/Klokka/

It is a small app and I have commented the Tasking part.

Regards
Preben Randhol
-- 
Preben Randhol ------------------------ http://www.pvv.org/~randhol/ --
�There are three things you can do to a woman. You can love her, suffer
 for her, or turn her into literature.�  - Justine, by Lawrence Durrell



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-15 16:25   ` evangeli
@ 2002-11-15 16:08     ` Preben Randhol
  2002-11-15 16:22     ` Jean-Pierre Rosen
  1 sibling, 0 replies; 7+ messages in thread
From: Preben Randhol @ 2002-11-15 16:08 UTC (permalink / raw)


evangeli wrote:
> thanks for your response
> i used protected type to prevent two tasks from making gtk calls at the 
> same time but that doesn't seem to work
> 
> any idea?

Yes show us how you do the GtkAda part of your program. I mean how do
you the Threading etc... It is hard to guess when we don't know what you
are doing.

-- 
Preben Randhol ------------------------ http://www.pvv.org/~randhol/ --
�There are three things you can do to a woman. You can love her, suffer
 for her, or turn her into literature.�  - Justine, by Lawrence Durrell



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-15 16:25   ` evangeli
  2002-11-15 16:08     ` Preben Randhol
@ 2002-11-15 16:22     ` Jean-Pierre Rosen
  1 sibling, 0 replies; 7+ messages in thread
From: Jean-Pierre Rosen @ 2002-11-15 16:22 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 535 bytes --]


"evangeli" <evangeli@cnam.fr> a �crit dans le message news:
3DD52006.8070308@cnam.fr...
> thanks for your response
> i used protected type to prevent two tasks from making gtk calls at the
> same time but that doesn't seem to work
>
> any idea?
>
Just to make sure...
Did you read the paragraph from the GTKAda user's guide which is
mysteriously titled: "Tasking with GTKAda" ?

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: multithreading with gtkada
  2002-11-14 17:59 ` Warren W. Gay VE3WWG
@ 2002-11-15 16:25   ` evangeli
  2002-11-15 16:08     ` Preben Randhol
  2002-11-15 16:22     ` Jean-Pierre Rosen
  0 siblings, 2 replies; 7+ messages in thread
From: evangeli @ 2002-11-15 16:25 UTC (permalink / raw)


thanks for your response
i used protected type to prevent two tasks from making gtk calls at the 
same time but that doesn't seem to work

any idea?


Warren W. Gay VE3WWG wrote:

> evangeli wrote:
> 
>> hi all
>>
>> it seems that gtk doesnt support multi-threading (see 
>> http://www.faqs.org/faqs/x-faq/part7/section-15.html).
> 
> 
> I believe that Gtk does support tasks, but on UNIX platforms,
> Gtk will make use of the Xlib (as the ref above shows). This
> library I believe is now thread safe on _some_ platforms,
> but most certainly NOT on all of them.  I would certainly
> not depend upon it for portable code.
> 
>> My problem is the following :
>> my app opens a windows, which on the show event launch a task wich 
>> makes a long computation. The window also contains a cancel button 
>> which can be pressed to abort this task.The problem is that i would 
>> like this task to make X-Call, and that is apparently not possible and 
>> give me unavoidably the following error message:
>> ----------------------------------------------
>> Xlib: unexpected async reply (sequence 0x9fe)!
>> ----------------------------------------------
>> i havent found any solution which doesn't use several tasks.
>>
>> 1) Am i clear?
>> 2) Do u have any idea of a different way to do that?
>> 3) why this cruel destiny?
>>
>> thanks for any response
> 
> 
> Your problem requires some careful Ada programming. You will need
> to segment your application so that one or the following
> approaches are used:
> 
>  - Only one task does Gtk (GUI) operations
> 
> or
> 
>  - You use an Ada technique to make certain that only one Ada task
>    is doing a Gtk operation at any given instance (protected objects
>    perhaps).
> 
> Sounds like you need the second approach. You can run into the same
> situations when trying to use curses (text mode screens).
> 




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-11-15 16:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-14 16:59 multithreading with gtkada evangeli
2002-11-14 17:59 ` Warren W. Gay VE3WWG
2002-11-15 16:25   ` evangeli
2002-11-15 16:08     ` Preben Randhol
2002-11-15 16:22     ` Jean-Pierre Rosen
2002-11-14 18:41 ` David Marceau
2002-11-14 22:00 ` Preben Randhol

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox