help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Questions about sockets and processes


From: Brett Cundal
Subject: [Help-smalltalk] Questions about sockets and processes
Date: Thu, 12 Feb 2004 22:23:57 -0800
User-agent: Mutt/1.5.5.1+cvs20040105i

Hiya,

I'm playing around with 2.1.7 and seeing some strange behavior...

Here's the setup:

st> Smalltalk at: #sock put: (TCP ServerSocket port: 3000) !
ServerSocket new "<0x40319130>"

So, I have a server socket listening on port 3000 now. I can do this
to block until a connection appears:

st> sock waitForConnection !

...this just sits there until I connect to port 3000. Good so far.

Now let's loop accepting connections and closing them immediately:

st> [ sock waitForConnection. sock accept close ] repeat !

Okay? This works fine and doesn't spin the CPU unless I hit control-C,
in which case it pegs the CPU at 100% - why is that?

Next (after killing gst and restarting), I'm trying to run this
listening process as a separate thread:

st> Smalltalk at: #sock put: (TCP ServerSocket port: 3000) !
ServerSocket new "<0x40319130>"
st> [ [ sock waitForConnection. sock accept close ] repeat ] forkAt:
Processor lowIOPriority !

Okay... this backgrounds and appears to be fine, but when I connect to
the port, it will not disconnect, it just waits. The thread is not
running.

I have to run the following to get any action:

st> Processor yield !

This allows the other thread to run once until it yields, but after
that I'm stuck at the prompt again with no other thread allowed to
run. I have to yield repeatedly to process multiple connections. Doing
this:

st> [ Processor yield ] repeat !

...seems to make everything work as expected. Connections are handled
promptly by the other thread.

Is this the correct thing to do if I want other threads to run?
Shouldn't the prompt automatically yield after displaying? Is it in
some sort of halting debug mode by default? Why does it keep hogging
the "Processor" even after an explicit yield? It appears to be getting
more than its fair time slice...

Care to enlighten me? :)

-- Brett

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]