If I CreateNewProcTags() with NP_Child, TRUE,
is it safe to share interface handles with the child,
or should that child process OpenLibrary() and GetInterface() it's own stuff?
I would _THINK_ it's OK to share, but I'll ask to be sure.
If I CreateNewProcTags() with NP_Child, TRUE,
is it safe to share interface handles with the child,
or should that child process OpenLibrary() and GetInterface() it's own stuff?
I would _THINK_ it's OK to share, but I'll ask to be sure.
For most libraries it is ok, but check the docs for exceptions. Most popular exception is bsdsocket.library, it requires you to OpenLibrary in each sub-task.
I don't think that NP_Child makes any difference.
On a couple of my dockies (KeymapSwitcher and DateTime) The opening/use of prefs. window is a separate process, and I use classes/gadgets/libs opened by the main (init.c) program.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Thank You both.
Regarding NP_Child.. Without that tag the Parent can terminate before the child. I expect the parent to close any libraries it opened, and that might be "bad" if the child is still using them.
After a closer look at the autodocs and a few emails from a helpful developer, I have decided that the new child process will open it's own libraries. There are some cases where it's not necessary, but I'd much rather go the safer and simpler route.
LyleHaze
Most cases it's okay.
In theory you should Obtain() the inetrface again from the child, (and Release() it before exit. This prevents it from being expunged and so means the parent can actualy close the library, should it need to exit before the child. Ofcourse that assumes the library is written properly....
Some librraies do definetly require process specific opens (bsd.socket being the most famous as Thomas pointed out).
Closing libraries is part of the main program (if it is properly written), but NP_Child only takes effect when the main program has already quit. So the libraries are closed anyway, no matter if you specify NP_Child or not. NP_Child is really only about the code. You have to take care of the libraries (and other shared resources) yourself.
You could for example create a SignalSemaphore in your main program. Each child process does ObtainSemaphoreShared when it starts. Before the main program frees any resources if does ObtainSemaphore (i.e. exclusive) so it will stop until all children have left.