Is it ok using WaitForChildExit(0) this way?

5 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 2013-05-30 00:53
Is it ok using WaitForChildExit(0) this way?

Hi, I open some window using CreateNewProcTags()

and then when quitting main program I use:

  1. ...
  2. if(/*dd->win[WID_MAIN]==NULL &&*/ dd->WinProc) {
  3. IExec->Signal( (struct Task *)dd->WinProc, SIGBREAKF_CTRL_F );
  4. }
  5.  
  6. if(/*dd->win[WID_PREFS]==NULL &&*/ dd->PrefsProc) {
  7. IExec->Signal( (struct Task *)dd->PrefsProc, SIGBREAKF_CTRL_F );
  8. }
  9.  
  10. IDOS->WaitForChildExit(0);
  11. ...

is it ok?

Or "better" GetPID() of win/prefs process and then " IDOS->WaitForChildExit();"

TiA

cwenzel
cwenzel's picture
Offline
Last seen: 1 week 5 days ago
Joined: 2021-01-12 07:05
Re: Is it ok using WaitForChildExit(0) this way?

There is no point in specifying a particular PID unless that's a feature you actually need.
As long as the parent process created all child processes with NP_Child,TRUE
then DOS knows which child process/es are created by this main parent process.

So, WaitForChildExit(0); is perfectly fine for ANY and ALL child processes
created by the parent, that may still be running, be that none or one or any number.

As long as you call it from the spawning parent process before leaving main() or _start().
Otherwise a child could still be running in freed memory when the main program unloads,
which is never going to end well.

PS: I would enclose those two tests and the signalling calls within Forbid() / Permit() block,
because the pointer check may become invalid in between the test and the Signal() calls.
So Forbid() at line 1 and Permit() at line 9.

jabirulo
jabirulo's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 2013-05-30 00:53
Re: Is it ok using WaitForChildExit(0) this way?

THX for explanation. Added Permit/Forbid funcs.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

hypex
hypex's picture
Offline
Last seen: 2 days 16 hours ago
Joined: 2011-09-09 16:20
Re: Is it ok using WaitForChildExit(0) this way?

@ cwenzel

PS: I would enclose those two tests and the signalling calls within Forbid() / Permit() block

I thought using Forbid() / Permit() was forbidden or highly advised against on the modern age?

cwenzel
cwenzel's picture
Offline
Last seen: 1 week 5 days ago
Joined: 2021-01-12 07:05
Re: Is it ok using WaitForChildExit(0) this way?

In the past it was used in situations that could be avoided which caused problems.
Stopping multi-tasking should not be taken lightly, but in some cases there is no
other way. For example, there is no global message port locking semaphore
and no way to stop another task running that may be about to zero out a shared
pointer from another task.

Sometimes it is still required, but only when there 's a risk of a multi-threaded
program resource going away at the worst time. (Like the above example).
Of course, it should only be used in these sort of extremely quick operations,
like Signal() and PutMsg() to make sure the pointer doesn't go stale in
the few microseconds between the test and the call.

Log in or register to post comments