/** Block for and get any final results from a dfork'd MRTask2. * Note: the desired name 'get' is final in ForkJoinTask. */ public final T getResult() { try { try { ForkJoinPool.managedBlock(this); } catch (InterruptedException e) { } return self(); }catch(Throwable t){ throw new RuntimeException(t); } }
/** Block this thread until all prior remote PUTs complete - to force * remote-PUT ordering on the home node. */ void startRemotePut() { assert !_key.home(); int x = 0; // assert I am waiting on threads with higher priority? while( (x=_rwlock.get()) != -1 ) // Spin until rwlock==-1 if( x == 1 || RW_CAS(0,1,"remote_need_notify") ) try { ForkJoinPool.managedBlock(this); } catch( InterruptedException e ) { } }
public static void reserveTaskMem(long m){ final long bytes = m; while(!tryReserveTaskMem(bytes)){ try { ForkJoinPool.managedBlock(new ManagedBlocker() { @Override public boolean isReleasable() {return _taskMem.get() >= bytes;} @Override public boolean block() throws InterruptedException { synchronized(_taskMemLock){ try {_taskMemLock.wait();} catch( InterruptedException e ) {} } return isReleasable(); } }); } catch (InterruptedException e){throw Log.errRTExcept(e); } } }
public T invoke( Key... keys ) { try { ForkJoinPool.managedBlock(dfork(keys)); } catch(InterruptedException iex) { Log.errRTExcept(iex); } // Intent was to quietlyJoin(); // Which forks, then QUIETLY join to not propagate local exceptions out. return self(); }
@Override public V get() { // check priorities - FJ task can only block on a task with higher priority! Thread cThr = Thread.currentThread(); int priority = (cThr instanceof FJWThr) ? ((FJWThr)cThr)._priority : -1; // was hitting this (priority=1 but _dt.priority()=0 for DRemoteTask) - not clear who increased priority of FJWThr to 1... // assert _dt.priority() > priority || (_dt.priority() == priority && (_dt instanceof DRemoteTask || _dt instanceof MRTask2)) assert _dt.priority() > priority || ((_dt instanceof DRemoteTask || _dt instanceof MRTask2)) : "*** Attempting to block on task (" + _dt.getClass() + ") with equal or lower priority. Can lead to deadlock! " + _dt.priority() + " <= " + priority; if( _done ) return result(); // Fast-path shortcut // Use FJP ManagedBlock for this blocking-wait - so the FJP can spawn // another thread if needed. try { try { ForkJoinPool.managedBlock(this); } catch (InterruptedException e) { } } catch(Throwable t){ // catch and rethrow to preserve the stack trace! throw new RuntimeException(t); } if( _done ) return result(); // Fast-path shortcut assert isCancelled(); return null; } // Return true if blocking is unnecessary, which is true if the Task isDone.
ForkJoinPool.managedBlock(node); } catch (InterruptedException ie) { node.wasInterrupted = true;
/** This value was atomically extracted from the local STORE by a successful * TaskPutKey attempt (only 1 thread can ever extract and thus call here). * No future lookups will find this Value, but there may be existing uses. * Atomically set the rwlock count to -1 locking it from further GETs and * ship out invalidates to caching replicas. May need to block on active * GETs. Updates a set of Future invalidates that can be blocked against. */ Futures lockAndInvalidate( H2ONode sender, Futures fs ) { assert _key.home(); // Only the HOME node for a key tracks replicas // Write-Lock against further GETs while( true ) { // Repeat, in case racing GETs are bumping the counter int old = _rwlock.get(); assert old >= 0 : _key+", rwlock="+old; // Count does not go negative assert old != -1; // Only the thread doing a PUT ever locks if( old !=0 ) { // has readers? // Active readers: need to block until the GETs (of this very Value!) // all complete, before we can invalidate this Value - lest a racing // Invalidate bypass a GET. try { ForkJoinPool.managedBlock(this); } catch( InterruptedException e ) { } } else if( RW_CAS(0,-1,"wlock") ) break; // Got the write-lock! } // We have the set of Nodes with replicas now. Ship out invalidates. int max = _replicas.length(); for( int i=0; i<max; i++ ) if( _replicas.contains(i) && H2ONode.IDX[i] != sender ) TaskInvalidateKey.invalidate(H2ONode.IDX[i],_key,fs); return fs; }
ForkJoinPool.managedBlock(node); } catch (InterruptedException ie) { node.wasInterrupted = true;