Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to execute procedure in the background ??

598 views
Skip to first unread message

JaMEs CoRN 0.0.7.

unread,
Jul 11, 1996, 3:00:00 AM7/11/96
to

Hi all..
let's say I have a self-defined Tcl procedure GETPOSN :

GETPOSN {
while {} {
... assign values to global variables
}
}

values are returned from a server program in the while loop and these values are
assigned to global variables to be used in the execution of the program .. is there a
way I can make the procedure GETPOSN run in the background ??

ps : I'm new to Tcl .. TIA for any help ...
--
.__J.a.M.E.s...c.0.R.n..000..000..111.__.
: email: james...@pobox.org.sg :
:_web: http://www.iscs.nus.sg/~tanpuayh_:

Frederic Bonnet

unread,
Jul 11, 1996, 3:00:00 AM7/11/96
to

JaMEs CoRN 0.0.7. wrote:
>
> Hi all..
> let's say I have a self-defined Tcl procedure GETPOSN :
>
> GETPOSN {
> while {} {
> ... assign values to global variables
> }
> }
>
> values are returned from a server program in the while loop and these values are
> assigned to global variables to be used in the execution of the program .. is there a
> way I can make the procedure GETPOSN run in the background ??

No, at least in standard Tcl.
I think the BLT extensions provide a way to evaluate scripts in the background.

I guess you use sockets to communicate with the server. In this case you can use
fileevents on sockets, in order to call a handler in the background each time the
server sends a value.

Regards, Fred

--
Frederic BONNET Eleve-Ingenieur de l'Ecole des Mines de Nantes
fbo...@irisa.fr Stagiaire IRISA - Projet Solidor

"Il ne faut jamais remettre au lendemain ce qu'on peut faire le surlendemain"
Oscar WILDE

JaMEs CoRN 0.0.7.

unread,
Jul 12, 1996, 3:00:00 AM7/12/96
to

JaMEs CoRN 0.0.7. (tanp...@iscs.nus.sg) wrote:
: values are returned from a server program in the while loop and these values are

: assigned to global variables to be used in the execution of the program .. is there a
: way I can make the procedure GETPOSN run in the background ??

something to add on ... I would like GETPOSN to run in the background, or better
still, to run as a separate thread that is created at the start of the program.. is there
a way to do this ??.. TIA.

Yves Mathys

unread,
Jul 12, 1996, 3:00:00 AM7/12/96
to

>>>>> "JaMEs" == JaMEs CoRN 0 0 7 <tanp...@iscs.nus.sg> writes:
In article <4s2dou$c...@nuscc.nus.sg> tanp...@iscs.nus.sg (JaMEs CoRN 0.0.7.) writes:


JaMEs> Hi all..
JaMEs> let's say I have a self-defined Tcl procedure GETPOSN :

JaMEs> GETPOSN {
JaMEs> while {} {
JaMEs> ... assign values to global variables
JaMEs> }
JaMEs> }

JaMEs> values are returned from a server program in the while loop and these values are
JaMEs> assigned to global variables to be used in the execution of the program .. is there a
JaMEs> way I can make the procedure GETPOSN run in the background ??

Look at 'after' command to push procedure on the event queue.

-Yves
--

Yves Mathys Europe Design Technology
mat...@ssdtgva.sps.mot.com High Level Modeling
Motorola Inc
Phone: (41-22) 799 12 28 207, route de Ferney/CP 15
FAX: (41-22) 799 13 04 1218 Grand-Saconnex,Switzerland


Donal K. Fellows

unread,
Jul 15, 1996, 3:00:00 AM7/15/96
to

In article <4s4aqe$a...@nuscc.nus.sg>,

JaMEs CoRN 0.0.7. <tanp...@iscs.nus.sg> wrote:
> JaMEs CoRN 0.0.7. (tanp...@iscs.nus.sg) wrote:
>> values are returned from a server program in the while loop and
>> these values are assigned to global variables to be used in the
>> execution of the program .. is there a way I can make the procedure

>> GETPOSN run in the background ??
>
> Something to add on ... I would like GETPOSN to run in the

> background, or better still, to run as a separate thread that is
> created at the start of the program.. is there a way to do this?

You are not thinking in event-based terms.

If the values from the server are arriving on channel ServerChan (a
socket or pipe), then you want to arrange for a procedure to be called
every time a new value is available from ServerChan. This means that
you need to do a bit of coding with fileevent

proc getOnePosn {} {
global ServerChan
if {[gets $ServerChan line] < 0} {
close $ServerChan
# The server has gone away!?
} else {
# ... Do Something with the line just read ...
}
}
fileevent $ServerChan readable getOnePosn

Now you need to make sure that you enter the Tcl event loop (Tk event
loop for 7.4/4.0) using tkwait or vwait.

Donal.
--
Donal K. Fellows, (at work) | Donal K. Fellows, (at home)
Dept. of Computer Science, | 6, Randall Place, Heaton,
University of Manchester | Bradford, BD9 4AE
U.K. Tel: ++44-161-275-6137 | U.K. Tel: ++44-1274-401017
fell...@cs.man.ac.uk (preferred) | do...@ugglan.demon.co.uk (if you must)
--------------------------------------------------------------------------
<http://r8h.cs.man.ac.uk:8000/> for my home page

Nenad Cimerman

unread,
Jul 16, 1996, 3:00:00 AM7/16/96
to

In article <31E53621...@irisa.fr>, Frederic Bonnet <fbo...@irisa.fr> writes:
|> JaMEs CoRN 0.0.7. wrote:
|> >
|> > Hi all..
|> > let's say I have a self-defined Tcl procedure GETPOSN :
|> >
|> > GETPOSN {
|> > while {} {

|> > ... assign values to global variables
|> > }
|> > }
|> >
|> > values are returned from a server program in the while loop and these values are
|> > assigned to global variables to be used in the execution of the program .. is there a
|> > way I can make the procedure GETPOSN run in the background ??
|>

Maybe it's even not such a very good idea to modify global variables from
the background ... How about using the 'send'-command from a seperate script,
which can be started like: exec ListenToServer.tcl
You could implement callback functions for received data and call them
remotely via the send-command (see man-page).

Another way to perform background tasks is to use the 'after'-command:

proc SayHi {} {
puts stdout 'Hi there'

after 1000 SayHi
}


SayHi

Bye,
--
Nenad Cimerman

+---------------------------------------------------------------------------+
| Nenad Cimerman, Informatiker Abteilung EM (EM Dept.) |
+---------------------------------------+-----------------------------------+
| H.Stoll GmbH & Co. | phone : +49 (0)7121/313-346 |
| Stollweg 1 | fax : +49 (0)7121/313-110 |
| 72760 Reutlingen (Germany) | e-mail: ni...@stoll.de |
+---------------------------------------+-----------------------------------+

0 new messages