Yes, it would lose you the ability to parallelize. There may be a way
out of this: Have the following system call:

public class System {
    public static <R> R unsafe(do R closure) { return closure; }
}

The above code would not compile (you may not let a 'do' parameter
escape, but the method is hardcoded into the class library so that it
does in fact compile. You can now remove the 'you may not let your
closure escape' clause, at your own peril, by unlinking it like so:

Runnable youCanStoreMeNow = unsafe(parameter);

The unsafe method would explain in the javadoc that you need to take
on ALL RESPONSIBILITY to transport any long effects back to the
originating thread. So, you need to transport any and all exceptions
that fall out of youCanStoreMeNow back to the originating thread, and
the same goes for the throwables that are used to implement long break/
return/continue (see the BGGA proposal for more details on those).
This is clearly 'here be dragons' territory, but how often exactly
does one write a library for parallelizing things? Maybe like 5 times
in the entire world? Doesn't everyone else just use forkjoin? So, I'm
perfectly allright with having the type system be no help whatsoever
to you in the exceedingly rare circumstance when the rocket scientists
go write this function.

On Aug 19, 8:58 am, Ben Schulz <ya...@gmx.net> wrote:
> > I'd much rather have a closure proposal where a method that takes a
> > closure that has tennant's correspondence principle is strictly
> > enforced by the compiler to keep the closure stack-safe. In other
> > words, legal operations are:
>
> > 1. Running the closure,
> > 2. Grabbing info off of the closure object (running its toString or
> > some such)
> > 3. passing it on to another method that accepts closures.
>
> Wouldn't you lose the ability to parallelize? I might want to find an
> element in a collection that satisfies a certain predicate. The
> "first" thread to find one gets to return its findings, the others are
> ignored.
>
> With kind regards
> Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to