Search the web
Sign In
New User? Sign Up
iolanguage · Io
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Io Synchronization   Message List  
Reply | Forward Message #363 of 11910 |
Re: [Io] Io Synchronization


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




Thu Dec 5, 2002 1:59 am

stevedekorte
Offline Offline
Send Email Send Email

Forward
Message #363 of 11910 |
Expand Messages Author Sort by Date

How does synchronization work in Io? In Java for example you can 'synchronize' a method or a block which prevents multiple threads from entering this section...
kgrgreer
Offline Send Email
Dec 3, 2002
5:36 pm

... Kevin, Io uses light weight threads (aka. coroutines, aka. user threads) for concurrency. These are cooperative(you call "yield" to yield to other threads)...
Steve Dekorte
stevedekorte
Offline Send Email
Dec 3, 2002
9:59 pm

... Steve, 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...
kgrgreer
Offline Send Email
Dec 4, 2002
10:27 pm

... For the most part, yes, unless your method calls something which in turn calls yield. ... That's right. The Socket addons use asynchronous socket calls and...
Steve Dekorte
stevedekorte
Offline Send Email
Dec 5, 2002
1:59 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help