home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18309 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  6.2 KB

  1. Path: sparky!uunet!gossip.pyramid.com!pyramid!oracle!unrepliable!bounce
  2. From: dnavas@oracle.uucp (David Navas)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: IPC and shared memory
  5. Message-ID: <1993Jan7.203535.11473@oracle.us.oracle.com>
  6. Date: 7 Jan 93 20:35:35 GMT
  7. References: <1ib8dmINNesj@uwm.edu> <paulk.33x6@terapin.com> <1ifq0hINNak2@uwm.edu>
  8. Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
  9. Organization: Oracle Corporation, Redwood Shores CA
  10. Lines: 119
  11. Nntp-Posting-Host: mailseq.us.oracle.com
  12. X-Disclaimer: This message was written by an unauthenticated user
  13.               at Oracle Corporation.  The opinions expressed are those
  14.               of the user and not necessarily those of Oracle.
  15.  
  16. In article <1ifq0hINNak2@uwm.edu> bloc1469@ee.ee.uwm.edu (Gregory R Block) writes:
  17. >Interesting.  So why not just have a server process which does the
  18. >tracking of stuff, and use either spawned slaves, or use a separate
  19. >binary for a slave and have the server send you a pointer to it?  That
  20.  
  21. Or, if each slave is just being used to handle some state, and it's the
  22. server that's performing all the work, run the slaves in the server's
  23. process context.  This depends a lot on what kind of code you already have
  24. set up.
  25.  
  26. I've always tried to think of these types of problems in an "object-oriented"
  27. manner (I put this in quotes to avoid needless finnagling about what
  28. object-oriented does or does not mean).  If I'm understanding correctly,
  29. each of these 'slaves' has its own I/O ports to the separate users, but
  30. the game-code itself needs to reside in one separate place and communicate
  31. with everybody else.
  32.  
  33. Assuming that things aren't quite so simple (the slaves might have
  34. different I/O requirements, etc.), I would view each type of slave as a
  35. subclass of the server.  Here, the 'state' of the server would be thought of as
  36. the server class' 'class-variables', and the state of each  slave would be
  37. kept in the process-instance of the slave (or perhaps in the slave's
  38. class-variables, depending on your implementation).
  39.  
  40. Now why have I introduced this seemingly messy representation into a
  41. discussion that has already produced several good answers?
  42.  
  43. Well, chew a minute on this:
  44.  
  45. Let's say that one of the methods you've defined in your server-class is
  46. METH_GET_MAP -- which might get you a pointer to some kind of shared map.
  47. Let's say that we define this method to run synchronously to the caller --
  48. the slaves in this case.
  49.  
  50. The method itself might look like:
  51.     APTR MethGetMap(METHOD_ARGS)
  52.         {
  53.        PSem(MyGlobalMap, SSEM_LOCK);
  54.            return MyGlobalMap;
  55.         }
  56.  
  57. [Note: this code would reside in the server-process only, and I'm assuming
  58.  the existance of a global variable "MyGlobalMap"]
  59.  
  60. Each slave, having appropriately sub-classed the server-class, could then
  61. invoke the method on itself:
  62.     map = DoShadowMethod(MySlaveObject, NULL, METH_GET_MAP, METHOD_END);
  63.  
  64. [Note: this code in the slave.]
  65.  
  66. Notice -- the method is invoked within the slave-process-context, so the
  67. semaphore is requested/owned by the slave.  The code, however, exists within
  68. the server, and hence has access to the server's variables.
  69.  
  70. Once you have the map pointer, you can diddle as much as you like with it,
  71. and then call some kind of method to release the semaphore -- or, considering
  72. this particular implementation, you can call "VSem(map);" directly.
  73.  
  74. What advantages over using an IPCMessage for this?
  75.     1) The semaphore code can be hidden in the server, where knowledge
  76.        about access arguably belongs.
  77.     2) You don't have to create two IPCPorts to handle the messages.
  78.     3) You (may or may not) have the overhead of a task switch.
  79.     4) You can change the way the code behaves (what process the method
  80.        is synchronous to) during the programming phase -- compare this
  81.        with rewriting event-loops.
  82.     5) You don't have to write multiple-event-loops (or worse, your
  83.        own thread-code ala AmigaOS filesystem) to avoid dead-lock
  84.        situations.  Note that this doesn't elminate dead-locks, but
  85.        because of 4) above, your life will be easier.
  86.     6) You keep code and data usage down.
  87.  
  88. >enables you to do LOTS of things by having the "master" know
  89. >everything that's going on, and having the slave be that user's
  90.  
  91. That, however, is exactly what I wouldn't want to have happen.  Because then
  92. you get in the business of one process keeping several process' state
  93. updated, and as master-slave process integration increases, you start having
  94. fun discussions about how to keep the master and the slave's idea of the
  95. slave's state synchronized.
  96.  
  97. Obviously, with a simple example like semaphore sharing, this is not a problem,
  98. but things can get more complicated, and hence more hairy.  That way lies
  99. sleepless nights....  :)
  100.  
  101. >interface to the world.  One could write slaves that are nothing more
  102. >than "windows to the world" for the users of the bbs.  More
  103.  
  104. Yes, slaves as subclasses -- specialized versions of the server program
  105. that package both the users' code differences (if any) from the server,
  106. and the users' separate states.
  107.  
  108. >importantly, one could write "AI slaves" as seen in muds, robots if
  109. >you will, or perhaps highly intelligent monsters.  It all depends on
  110. >how you're designing the game, but it does sound as if you could
  111. >benefit from having a master process with either subprocesses (perhaps
  112. >your bbs could call an AREXX script which launched a slave or
  113. >something) or as separate slaves (the more complex but more powerful
  114. >solution).
  115.  
  116. The other problem with this discussion is that there seems to be an inherent
  117. assumption that different programs == different processes.  First of all,
  118. AmigaOS does have the concept of a library -- you could stick your
  119. semaphore someplace in the libraryBase.  Second of all, it's not unreasonable,
  120. as shown above, that slave processes would have access (in whatever way)
  121. to some other program's global variables.  That's one of the FEATURES of
  122. AmigaOS ;)
  123.  
  124. >Who knows.  :)
  125.  
  126. Well, I won't claim omniscience, but I will claim experience.  All of my
  127. Amiga programming has been this kind of master-slave programming we're
  128. discussing here.  I don't think I've ever written a standalone, mono-process
  129. program for the Amiga....  Hm....
  130.  
  131. Of course, I'm still young, so what do I know :) :) :)
  132.  
  133. David C. Navas                        dnavas@oracle.com
  134. Working for, but not speaking on behalf of, Oracle Corp.
  135.