/* Copyright Per Bothner 1987. Read the file Q-INFO */


EvalProcBody(var, body)
    Func body;
{
    int more_potential_answers;
    x_IF
    ObEqu(var, Apply(body, NoValue));
 if anyone is waiting -- reply to them?
 or do the reply in Unify?
 /* one answer returned; wait for request for more answers */
    more_potential_answers = ...;
    DoNotifications(var, more_potential_answers);
    if (more_potential_answers)
	Reply(msg, Receive(msg));
	_RAISE_
    x_THEN
    if 
    x_ELSE
    mark as failed
    x_FI
    wait for subprocess to finish
}

Object DerefVar(var)
    struct Variable *var;
  { struct ParVar *curVar; MsgStruct msg[1];
    if (!IsVariable(var)) return (Object)var;
  retry:
    if (var->value != NULL && !var->flags & more_potential) return var->value;
    curVar->wait.self = curVar;
    curVar->wait.controller = WaitControllerMagic;
 /* RACE CONDITION! Next two statements should be done atomically! */
    LinkNewDependent(var, &curVar->wait);
  new_value:
    awaker = Receive(msg); Reply(msg, awaker);
if process-finished RAISE();
    if (msg->sysCode & more_potential_replies)
	goto retry;
	|
	{
	    msg->sysCode = get_more_replies;
	    Send(msg, awaker);
	    if failed: RAISE
	    goto new_value;
	}
     else goto retry;
  }
