home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!rutgers!cbmvax!dlarson
- From: dlarson@cbmvax.commodore.com (Dale Larson)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Enough talk. FILE: server.c
- Message-ID: <38418@cbmvax.commodore.com>
- Date: 8 Jan 93 17:08:37 GMT
- References: <C0IyF5.9Gv@usenet.ucs.indiana.edu>
- Reply-To: dlarson@cbmvax.commodore.com (Dale Larson)
- Organization: Commodore Engineering
- Lines: 71
-
- In article <C0IyF5.9Gv@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu writes:
- > Forbid();
- > myport = FindPort("Foobar!"); /*Is the server already running..? */
- > Permit();
-
- You shouldn't Permit() here. If you do, the Forbid() does no good at all.
-
- > if (myport) /* Yup */
- > {
- > if (EasyRequest(NULL, &ereq[SERVER_RUNNING], NULL))
- > shutdown(myport); /* Either shut down */
- > else /* Or remain running */
- > {
- > CloseLibrary(GfxBase);
- > CloseLibrary(IntuitionBase);
- > exit(0);
- > }
- > } /* If we don't exist, */
- > if (!(myport = CreateMsgPort())) /* Create the port.. */
- > {
- > Alert(AN_CreatePort);
- > exit(0);
- > }
-
- You should Permit() here.
-
- It would be a good idea to rearrange this code thusly in order to make it more
- clear and to minimize the amount of time spent under Forbid()::
-
- Forbid();
- /* ********************************************************************
- ** Begin Critical section:
- ** We don't want another server starting here!
- */
- serverport = FindPort(...
- if(!serverport) /* We are the only server */
- {
- myport=CreateMsgPort(...
- }
- /*
- ** End Critical section:
- ** If there is another server, we will exit soon. If not and
- ** another server is started at this point, it will just exit.
- *********************************************************************/
- Permit();
- if(serverport) /* A server already exists */
- {
- CloseLibrary(...
- exit(0);
- }
- if(!myport) /* We are the only server, but can't CreateMsgPort() */
- {
- Alert(AN_CreatePort);
- exit(0);
- }
- ...
-
-
-
- > // Amiga 3000 ___ \ Sam Hulick: shulick@indiana.edu (NeXTmail OK!)
- > // 68030 25 MHz /__/\ \ My opinions wear combat boots. Or whatever.
- >\\// OS 2.04 \__\/ / "Walk! Not bloody likely. I am going in a
- > \/ / taxi." --George Bernard Shaw
-
-
- --
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Dale Larson, Software Engineer | "Elegance increases reliability
- dlarson@commodore.com | and maintainability."
-
- Disclaimer: I'm not Commodore's mouthpiece!
-