Oz and Mozart Users Mailing List

Re: Time.delay


From: Denys Duchier (Denys.Duchier@ps.uni-sb.de)
Date: Fri Aug 03 2001 - 13:54:24 CEST


Hi Johann

big.john@bigfoot.com (Johann Höchtl) writes:

> As a beginner i have written the following short program :

the reason for your problem is quite simple: concurrent programming is
tricky. The current implementation of OS.accept is blocking: this
means the entire system blocks until the call completes. Since you
process the accepted connection in a new separate thread, it may or
may not reach OS.close before the main thread tries OS.accept again on
the next iteration. When you add the delay it turns out that the
accept is attempted before the close is reached, thus the entires
system is blocked until a new connection is accepted and the close
won't get a chance to happen until then.

One possibility is to use OS.acceptSelect before OS.accept to make
sure that there is a connection ready to be accepted. acceptSelect
will only block the thread performing it, but not the entire system.
See the documentation of module OS.

Concerning endless loops, you can use the syntax:

        for do ... end

Cheers,

> ------------------------
> functor
> import
> OS
> Application
> System
> define
> MySock = {OS.socket 'PF_INET' 'SOCK_STREAM' ""}
> proc {Out TSock}
> {OS.send TSock "Hallo Welt!" nil _}
> {System.printInfo "ping ... "}
> {Delay 5000}
> {System.showInfo "pong"}
> {OS.close TSock}
> end
> proc {Listen}
> local
> Csock
> in
> {System.showInfo "Waiting for connections..."}
> Csock = {OS.accept MySock _ _}
> thread
> {Out Csock}
> end
> {Listen}
> end
> end
> in
> {OS.bind MySock 60028}
> {OS.listen MySock 3}
> {Listen}
> {OS.close MySock}
> {Application.exit 0}
> end
> ------------------------
>
> but when i compile (ozc -c file.oz) and execute (ozengine file.ozf) it
> hangs in the call to {Delay 5000}; that means the eg. telnet client
> gets the string but the connection is not closed after 5 sec.; when i
> remove the Delay -call everything is fine.
>
> Delay on its own works also fine.
>
> ? What's wrong with delay
>
> I did not found any syntactic support for endless loops. Are
> tail-recursive procedures the correct solution?
>
> Thank you,
> Johann
>
> -
> Please send submissions to users@mozart-oz.org
> and administriva mail to users-request@mozart-oz.org.
> The Mozart Oz web site is at http://www.mozart-oz.org/.

-- 
Dr. Denys Duchier			Denys.Duchier@ps.uni-sb.de
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.



This archive was generated by hypermail 2b29.