Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Clojure Design
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
Colour
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Undo
Redo
Keyboard Shortcuts Help
<h3>Problems</h3> <ul> <li>deref on some IDerefs can block. <ul> <li>futures</li> <li>promises</li> </ul> </li> <li>problem - If you can't accept blocking indefinitely you have no alternative</li> <li>some reference type might not yet have a value <ul> <li>futures</li> <li>promises</li> <li>delays</li> </ul> </li> <li>problem - if you need to make a decision based upon whether or not such a reference has a value you can't, without forcing/blocking</li> </ul> <h4>Possible solutions</h4> <ul> <li>categorize references that can block <ul> <li>e.g. IMightBlock</li> </ul> </li> <li>offer a deref with timeout <ul> <li>e.g. (deref blocking-ref timeout timeout-val)</li> </ul> </li> <li>categorize references that might not yet have a value <ul> <li>e.g. IMightNotHaveAValue</li> </ul> </li> <li>offer a query fn for that <ul> <li>(has-value? aref)</li> </ul> </li> </ul> <h4><strong>Issues</strong></h4> <ul> <li>which (if any) of these make sense for other refs? <ul> <li>timeout seems really confusing for non-blocking</li> <li>has-value? could be trivially true for other refs <ul> <li>but causes paranoia?</li> </ul> </li> </ul> </li> <li>overload deref for timeout, or new fn name?</li> </ul> <hr /> <h3>Wants</h3> <ul> <li>I want to know if a potentially blocking deref has a value <ul> <li><code>future-done?</code> for Future</li> <li><code>(.hasValue foo)</code> for Promise</li> </ul> </li> </ul> <ul> <li>I want to know if something has finished <ul> <li><code>await</code> for Agent</li> <li><code>future-done?</code> for Future</li> <li><code>Thread.isAlive</code> (rare)</li> </ul> </li> </ul> <ul> <li>I want to wait for something to finish <ul> <li><code>await</code> for Agent</li> <li><code>deref</code> for Future, Delay, and Promise</li> </ul> </li> </ul> <ul> <li>I want to wait a specific amount of time for something to finish <ul> <li><code>await-for</code> for Agent</li> </ul> </li> </ul> <ul> <li>I want to prevent something from happening <ul> <li><code>future-cancel</code> for Future</li> <li><code>ThreadPoolExecutor.remove</code> for a custom thread pool</li> <li>Avoid <code>deref</code> on a Delay</li> </ul> </li> </ul> <h3>Example Problem</h3> <ul> <li>printing at the REPL looks through a deref <ul> <li>this can block (possibly forever) if a data structure contains e.g. a promise</li> </ul> </li> <li>The REPL should not perform the deref for a print request unless there is a value <ul> <li>option 1: never deref possible blockers</li> <li>option 2: have a bindable val that controls how REPL prints blocking derefs, analogous to the controls for lazy data structures</li> </ul> </li> <li>in any case, there needs to be a way to discover which derefs have a value</li> </ul> <h3>Facts</h3> <ul> <li><code>deref</code> can block <ul> <li>Never for Var, Ref, Agent, and Atom</li> <li>Sometimes for Future, Delay, and Promise</li> </ul> </li> </ul> <ul> <li>Java APIs <ul> <li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html">Future</a> <ul> <li><code>.get()</code> blocks until complete <ul> <li>interruptible, throws InterruptedException</li> </ul> </li> <li><code>.get(long, TimeUnit)</code> blocks for specified duration <ul> <li>throws TimeouotException if it times out</li> <li>interruptible, throws InterruptedException</li> </ul> </li> <li><code>.isDone()</code> asks if finished</li> <li><code>.cancel(bool mayInterrupt)</code> attempts to cancel <ul> <li>if already finished or cancelled, returns false</li> <li>if already running, tries to interrupt if argument is true</li> </ul> </li> <li><code>.isCancellled()</code> asks if cancelled</li> </ul> </li> <li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CountDownLatch.html">CountDownLatch</a> <ul> <li><code>.await()</code> blocks until latch reaches zero <ul> <li>interruptible, throws InterruptedException</li> </ul> </li> <li><code>.await(long, TimeUnit)</code> blocks until latch reaches zero <ul> <li>returns false if it times out</li> <li>interruptible, throws InterruptedException</li> </ul> </li> <li><code>.getCount()</code> returns current count</li> </ul> </li> <li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Semaphore.html">Semaphore</a></li> <li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CyclicBarrier.html">CyclicBarrier</a></li> </ul> </li> </ul>
Attachments
Labels
Location
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced