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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!rutgers!cbmvax!dlarson
  2. From: dlarson@cbmvax.commodore.com (Dale Larson)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Enough talk.  FILE: server.c
  5. Message-ID: <38418@cbmvax.commodore.com>
  6. Date: 8 Jan 93 17:08:37 GMT
  7. References: <C0IyF5.9Gv@usenet.ucs.indiana.edu>
  8. Reply-To: dlarson@cbmvax.commodore.com (Dale Larson)
  9. Organization: Commodore Engineering
  10. Lines: 71
  11.  
  12. In article <C0IyF5.9Gv@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu writes:
  13. >   Forbid();
  14. >   myport = FindPort("Foobar!");  /*Is the server already running..? */
  15. >   Permit();
  16.  
  17. You shouldn't Permit() here.  If you do, the Forbid() does no good at all.
  18.  
  19. >   if (myport)  /* Yup */
  20. >   {
  21. >      if (EasyRequest(NULL, &ereq[SERVER_RUNNING], NULL))
  22. >         shutdown(myport);  /* Either shut down */
  23. >      else  /* Or remain running */
  24. >      {
  25. >         CloseLibrary(GfxBase);
  26. >         CloseLibrary(IntuitionBase);
  27. >         exit(0);
  28. >      }
  29. >   }                                   /* If we don't exist, */
  30. >   if (!(myport = CreateMsgPort()))  /* Create the port.. */
  31. >   {
  32. >      Alert(AN_CreatePort);
  33. >      exit(0);
  34. >   }
  35.  
  36. You should Permit() here.
  37.  
  38. It would be a good idea to rearrange this code thusly in order to make it more
  39. clear and to minimize the amount of time spent under Forbid()::
  40.  
  41.     Forbid();  
  42.     /* ********************************************************************
  43.     ** Begin Critical section:  
  44.     **    We don't want another server starting here! 
  45.     */
  46.     serverport = FindPort(...
  47.     if(!serverport)  /*  We are the only server */
  48.     {
  49.         myport=CreateMsgPort(...
  50.     }
  51.     /* 
  52.     ** End Critical section:  
  53.     **     If there is another server, we will exit soon.  If not and
  54.     **    another server is started at this point, it will just exit.
  55.     *********************************************************************/
  56.     Permit();  
  57.     if(serverport)  /*  A server already exists */
  58.     {
  59.         CloseLibrary(...
  60.         exit(0);
  61.     }
  62.     if(!myport)  /* We are the only server, but can't CreateMsgPort() */
  63.     {
  64.         Alert(AN_CreatePort);
  65.         exit(0);
  66.     }
  67.     ...
  68.  
  69.  
  70.  
  71. >    // Amiga 3000   ___ \ Sam Hulick: shulick@indiana.edu (NeXTmail OK!)
  72. >   // 68030 25 MHz /__/\ \ My opinions wear combat boots.  Or whatever.
  73. >\\// OS 2.04       \__\/ / "Walk!  Not bloody likely.  I am going in a
  74. > \/                     / taxi."  --George Bernard Shaw
  75.  
  76.  
  77. -- 
  78. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  79. Dale Larson, Software Engineer   |    "Elegance increases reliability
  80. dlarson@commodore.com            |    and maintainability."
  81.  
  82.             Disclaimer: I'm not Commodore's mouthpiece!
  83.