[comp.sys.amiga.tech] What's wrong with this picture??

wfischer@felix.UUCP (Bill Fischer) (11/21/90)

Assuming that program A started up program B by using the standard
technique of:
  
      LoadSeg()
      CreateProc()    /*  prog.foo  */
      PutMsg()

then program A should be able to 'freeze' program B, to temporarily
suspend it's operation by calling the following fuction:

FreezeProg() {

   Disable();
   tsk = (struct Task*)FindTask("prog.foo");
   Remove(tsk);
   tsk->tc_State = tsk->tc_State + 4;
   Enable();
   return(0);

}

And to 'unfreeze' (or restart) program B by calling the following
function:

MeltProg() {

   Disable();
   if (tsk->tc_State == 8)
       AddTail(&SysBase->TaskReady,tsk);
   else
       AddTail(&SysBase->TaskWait,tsk);
   tsk->tc_State = tsk->tc_State - 4;
   Enable();
   sig = tsk->tc_SigAlloc & tsk->tc_SigRecvd;
   if (sig != 0) Signal(tsk,sig);
   return(0);

}

The problem I have is that some programs don't come back to life
when I call MeltProg(). To make it even more complicated, the
programs that won't 'unfreeze', do so intermittently.... In
other words, sometimes they restart OK and sometimes they won't.
I might add that this technique worked pretty well under KS 1.3
but doesn't work AT ALL under 2.0. Am I breaking any rules here??
Under 2.0 I get a software error - task held requestor.

Regards  B F
  
..!hplabs!fritz!wfischer

jesup@cbmvax.commodore.com (Randell Jesup) (12/13/90)

	This is an old message, but there have been no responses to it.

In article <154108@felix.UUCP> wfischer@felix.UUCP (Bill Fischer) writes:
>Assuming that program A started up program B by using the standard
>technique of:
>  
>      LoadSeg()
>      CreateProc()    /*  prog.foo  */
>      PutMsg()
>
>then program A should be able to 'freeze' program B, to temporarily
>suspend it's operation by calling the following fuction:

	[ code that mucks with the exec task lists, etc ]

>And to 'unfreeze' (or restart) program B by calling the following
>function:

	[ function that adds task back to an exec list]

	Your meltlist call uses AddTail instead of Enqueue.  In any case,
mucking with exec task structures like this is _WRONG_.  Don't do it.
If you need mutual exclusion, there are plenty of safe ways to implement
it (Forbid() around critical sections, semaphores, etc, etc).

	If you're doing this to an external program you don't control,
you should rethink why you want to do this.

	Sorry if I seem adamant, but this really is off-limits.

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com  BIX: rjesup  
Thus spake the Master Ninjei: "If your application does not run correctly,
do not blame the operating system."  (From "The Zen of Programming")  ;-)