Sharing Interfaces with your children

6 posts / 0 new
Last post
LyleHaze
LyleHaze's picture
Offline
Last seen: 1 year 4 months ago
Joined: 2011-05-26 03:58
Sharing Interfaces with your children

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.

thomas
thomas's picture
Offline
Last seen: 1 day 8 hours ago
Joined: 2011-05-16 14:23
Re: Sharing Interfaces with your children

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.

jabirulo
jabirulo's picture
Offline
Last seen: 1 day 2 hours ago
Joined: 2013-05-30 00:53
Re: Sharing Interfaces with your children

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.

  1. ...
  2. if( (dd->PrefsProc = IDOS->CreateNewProcTags(
  3. NP_Entry, OpenPrefsWindow,
  4. NP_Name, LIBNAME"_prefs",
  5. NP_Child, TRUE,
  6. NP_EntryData, Self,
  7. ...

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

LyleHaze
LyleHaze's picture
Offline
Last seen: 1 year 4 months ago
Joined: 2011-05-26 03:58
Re: Sharing Interfaces with your children

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

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Sharing Interfaces with your children

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).

thomas
thomas's picture
Offline
Last seen: 1 day 8 hours ago
Joined: 2011-05-16 14:23
Re: Sharing Interfaces with your children

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.

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.

Log in or register to post comments