On Wednesday, December 4, 2002, at 02:27 PM, kgrgreer wrote:
> --- In iolanguage@y..., Steve Dekorte <steve@d...> wrote:
> Thanks for the explanation. So if I understand it correctly you
> don't need to synchronize sections of code, all you have to do is
> avoid calling yield() while you're in a criticial section and you are
> guaranteed that no other Coroutine/Actor will conflict with you.
For the most part, yes, unless your method calls something which in
turn calls yield.
> You
> could implement things like Semaphores using the pause() and resume()
> methods (in Object). I guess when you do IO and it blocks then it
> implicitly yield()'s for you?
That's right. The Socket addons use asynchronous socket calls and yield
while waiting for select() or timeouts.
> Is there any other way that you could
> be yield()'ed without explicitly calling yield()?
The only other places that comes to mind is that yield is called
between asynchronous messages and I might have put yields into the File
object to auto split up large reads and writes. If you want to be sure
that some method is only entered by one thread at a time you can get
this behavior by only calling it asynchronously.
> I guess this implies that as a good cooperator you should be calling
> yield() periodically to prevent the starvation of others.
That's right. Though I've considered adding an auto yield into the VM
that would get called every X message sends or something. Sort of like
how an OS switches threads except message lookups, gc, etc would be
assured to be atomic.
> If you were loading untrusted network code (like Java Applets or
> Mobile Agents) and you didn't trust the code to call yield, could you
> modify the definitions of things like 'while' and 'if' in the parent
> context to include calls to yield?
That's a good idea. I'd need to add the rawBlock() primitive method
first to allow user defined methods that access raw message arguments.
> Could you actually do something
> similiar to guard or secure things like File or Socket in order to
> create something like Java's Sandbox/SecurityManager setup?
A nice thing about Io for this stuff is that lookups always start at
the local scope and follow the proto&parent chains back to the Lobby.
So you could make your own isolated environment(a "Sandbox") in Io
simply by copying the Lobby, removing what you don't want to be visible
and remove it's proto slot - so it would be isolated from the rest of
the system.
It would be difficult to provide restricted access to a given object
though as Io's introspection APIs are difficult to override at the
moment.
Also, I need to change how doString works. It currently executes in the
context of the Lobby.
Cheers,
Steve
OSX freeware and shareware:
http://www.dekorte.com/downloads.html