Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eager-future2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vladimir Sedach
eager-future2
Commits
9297eeca
Commit
9297eeca
authored
14 years ago
by
Vladimir Sedach
Browse files
Options
Downloads
Patches
Plain Diff
Added README file w/documentation.
parent
76bb6863
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README
+128
-0
128 additions, 0 deletions
README
future.lisp
+2
-2
2 additions, 2 deletions
future.lisp
with
130 additions
and
2 deletions
README
0 → 100644
+
128
−
0
View file @
9297eeca
Eager Future2 is a Common Lisp library that provides composable
concurrency primitives that unify parallel and lazy evaluation, are
integrated with CL's condition system, and have automatic resource
management.
The basic unit of concurrency in Eager Future2 is the future, which is
a data type that acts as a proxy for the values of a no-argument
function (thunk) that is computed concurrently.
Eager Future2 provides several strategies for computing futures
(specified as keywords): :lazy (only computed when the future is asked
to yield its values), :speculative (may be computed when there is
processing capacity available), and :eager (computation begins as
soons as the future is created).
A future is created by the pcall function, which takes a thunk to
compute, and optionally the computing strategy. The default computing
strategy is specified by *default-future-type*, which is :speculative
by default.
A future can be asked for its values with the yield function. The
function ready-to-yield? is a non-blocking way to check whether the
future is done computing. The function select takes a set of futures
and blocks until at least one future is ready to yield, returning that
future.
Ongoing computation of a future can be aborted with the force
function, which takes the future and desired yield values and attempts
to install them in that future. If a future has already finished
computing, calling force on it will have no effect.
Error handling is done transparently (the same way as if the program
wasn't written to use futures) by proxying unhandled conditions and
available restarts across thread boundaries. An additional restart
called force-values is also offered, which simply calls force on the
future whose computation raised the error.
If a future is no longer referenced and gets garbage collected, any
ongoing computation associated with that future is aborted to release
underlying thread resources. This permits speculative computation to
be done without having to worry about manual resource management.
API documentation:
function pcall (thunk &optional (future-type *default-future-type*)) => future
Given a function of no arguments, returns an object (called a
future) that can later be used to retrieve the values computed by the
function.
future-type (by default the value of *default-future-type*) can either
be :eager, :speculative, or :lazy. See the documentation of
*default-future-type* for an explanation of the different future
types.
The function is called in an unspecified dynamic environment.
function ready-to-yield? (future) => nil or non-nil
Returns non-nil if the future values have been computed, nil otherwise.
function yield (future) => value*
Returns the computed values of the future.
In case of a delayed future, computes the value of the future in the
current thread.
In case of a speculative future, if no other thread is computing the
value of the future, computes the value in the current thread. If
another thread is currently computing the value of the future, blocks
until the value is available.
In case of an eager future, blocks until the value is available.
function select (&rest futures) => future
Returns the first future that is ready to yield.
function force (future &rest values) => nil
If the future has not yet yielded a value, installs the given
values as the yield-values of the future (stopping any ongoing
computation of the future).
macro pexec (&body body) => future
A shorthand for (pcall (lambda () ...)).
macro plet ((&rest bindings) &body body)
Like LET, but all bindings are evaluated asynchronously.
function iterate-futures (proc futures) => nil
Calls proc on each future in select order. Proc is a procedure that
takes the currently yieldable future as its first argument, and the
list of futures not yet processed as its second. Futures need to be
yielded by proc - this is done so that proc can have control of error
handling. The second argument is useful to for example be able to
terminate remaining computations before a non-local control transfer.
function force-all (futures &rest values) => nil
Calls force on all given future with values. Useful to stop
remaining computations in for example iterate-futures.
macro pand (&rest exprs) => t or nil
Evaluates expressions in parallel. If any expression yields nil,
terminates all outstanding computations and returns nil. If all
expressions yield a non-nil value, returns t.
macro por (&rest exprs) => nil or non-nil
Evaluates expressions in parallel. Returns the value of the first
expression that yields a non-nil value. If all expressions evaluate
to nil, returns nil.
function select-timeout (timeout &rest futures) => future or nil
Given a timeout (in seconds) and a set of futures, returns either
nil if no futures are ready to yield when timeout seconds have
elapsed, or the first yieldable future otherwise.
macro pfuncall (function &rest args) => result
Evaluates args in parallel before funcalling the given function on them.
This diff is collapsed.
Click to expand it.
future.lisp
+
2
−
2
View file @
9297eeca
...
...
@@ -18,7 +18,7 @@
(
or
(
slot-boundp
future
'values
)
(
error-descriptor
future
)))
(
defun
ready-to-yield?
(
future
)
"Returns
t
if the future values have been computed, nil otherwise."
"Returns
non-nil
if the future values have been computed, nil otherwise."
(
with-lock-held
((
lock
future
))
(
%ready-to-yield?
future
)))
...
...
@@ -64,7 +64,7 @@ computation of the future)."
(
condition-wait
notifier
select-lock
)))))
(
defun
yield
(
future
)
"Returns the computed value of the future.
"Returns the computed value
s
of the future.
In case of a delayed future, computes the value of the future in the
current thread.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment