added synchronization and thread shutdown procedures.

This commit is contained in:
gnembon committed 2020-01-14 14:23:33 -04:00
1 parent cfc71b845d
commit 316739c624
4 files changed
+61 -8

No files matched your search

@@ -2681,6 +2681,10 @@ public class Expression
* <h3><code>task_completed(task)</code></h3>
* <p>Returns true if task has completed, or false otherwise.</p>
*
* <h3><code>synchronize(lock, expression)</code></h3>
* <p>Evaluates <code>expression</code> synchronized with respect to the lock <code>lock</code>. Returns the value of the
* expression.</p>
*
* <hr>
* <h2>Auxiliary functions</h2>
*
@@ -3118,6 +3122,23 @@ public class Expression
return new NumericValue(((ThreadValue) v).isFinished());
});
addLazyFunction("synchronize", -1, (c, t, lv) ->
{
if (lv.size() == 0) throw new InternalExpressionException("'synchronize' require at least an expression to synchronize");
Value lockValue = Value.NULL;
int ind = 0;
if (lv.size() == 2)
{
lockValue = lv.get(0).evalValue(c);
ind = 1;
}
synchronized (ThreadValue.getLock(lockValue))
{
Value ret = lv.get(ind).evalValue(c, t);
return (_c, _t) -> ret;
}
});
addLazyFunction("system_variable_get", -1, (c, t, lv) ->
{
if (lv.size() == 0) throw new InternalExpressionException("'system_variable_get' expects at least a key to be fetched");