From starred@tiscalinet.it Wed Sep 26 17:32:30 2001
Received: from seneca.uniroma2.it (seneca.uniroma2.it [160.80.6.9])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8QFWTv08674;
	Wed, 26 Sep 2001 17:32:30 +0200 (MET DST)
Received: from penelope ([160.80.84.41])
	by seneca.uniroma2.it (8.9.3/8.9.1) with SMTP id QAA13968;
	Wed, 26 Sep 2001 16:32:34 +0100 (GMT+0100)
Organization: Universita' degli Studi di Roma "Tor Vergata"
              Centro di Calcolo e Documentazione - Servizio Reti
Message-ID: <001e01c146a1$c4cddfb0$295450a0@info.uniroma2.it>
From: "Armando Stellato" <starred@tiscalinet.it>
To: "Jan Wielemaker" <jan@swi.psy.uva.nl>,
   "SWI Mailing List" <prolog@swi.psy.uva.nl>
References: <3B77BB2F.4F1B3E45@tiscalinet.it> <01092616590902.19526@gollem>
Subject: Re: [SWIPL] How may I leave a PCE window available for input while a server is running on it?
Date: Wed, 26 Sep 2001 17:41:54 +0200
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

Thank you for your answer.
Just This morning i found an alternative solution, take a look and tell me
if it sounds "good".
I found the class timer (in xpce) and used it to send a message to prolog
every #milliseconds, letting @prolog use the predicate dispatch
for client-waiting.
In this way, the window is not busy anymore and, another important thing,
while timer continues to make prolog listen for clients, the predicate
dispatch can then deal with every client that connected to the server.
So, while SWI-prolog on windows is not multithreaded, the use of XPCE can
start multiple parallel prolog predicates from the same application, this is
kind of multitasking...even on windows...
This fact, combined with the broadcast-library providd with XPCE, can give
life to a complex agent-based environment!!
This the portion of code I modified wuth the introduction of the timer
class:

dispatch(_GUI) :-
 new(@dispatch_timer,timer(0.02,message(@prolog,dispatch1))),
 send(@dispatch_timer,start).

/*
 send(GUI,synchronise),        this portion of code is no more needed
 send(GUI,flush),
 dispatch1,
 !.
*/

dispatch1 :-
 findall(WriteStream,
agents:connection(_ClientId,_Socket,WriteStream,_ReadStream), Clients),
 listen_stream(Server),
 wait_for_input([Server|Clients],ReadyList, 0.015),
 (ReadyList \= [])
 ->
 format('ReadyList is: ~w~n',ReadyList),
 process_listen_queue(ReadyList)
 ;
% write(waiting),nl,flush_output,
 true.


Do you think it is a good solution???

Again, thank you.
Armando




----- Original Message -----
From: "Jan Wielemaker" <jan@swi.psy.uva.nl>
To: "Armando Stellato" <starred@tiscalinet.it>; "SWI Mailing List"
<prolog@swi.psy.uva.nl>
Sent: Wednesday, September 26, 2001 4:53 PM
Subject: Re: [SWIPL] How may I leave a PCE window available for input while
a server is running on it?


> On Mon, 13 Aug 2001, Armando Stellato wrote:
> >Hi,
> >I'm writing a Prolog-server on windows, so I can't use multitasking.
> >The problem is: if i make the server listening for inputs, he is busy
> >and I cannot access the window (the pointer is in the classic sand glass
> >shape). I'm using a repeat-loop to open a repetition of 0.55ms time
> >cells where the server is listening for clients. If I could add
> >something between the time cells for make the window listening for
> >manual inputs, the problem would be solved, but I don't know what.
> >Thank u in advance.
>
> You can clear the busy cursor using send(Frame, busy_cursor, @nil) and
> invoke send(@display, synchronise) from your loop to make the system
> look for events.  This call processes pending GUI events (if any) and
> returns immediately after doing so.
>
> This kind of programming is a bit nastly though.  Multi-threading or
> using multiple communicating Prolog applications probably gives more
> reliable results.  For example you could use one Prolog process doing
> the server work and control that from another doing the GUI work and
> contacting the server just like to other clients.
>
> Regards --- Jan

