home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18305 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.6 KB  |  87 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!gatech!concert!samba!usenet
  3. From: Todd_Lewis@unc.edu (Todd M. Lewis)
  4. Subject: Re: RKM description of WaitPort()
  5. Message-ID: <1993Jan7.201052.13703@samba.oit.unc.edu>
  6. Sender: usenet@samba.oit.unc.edu
  7. Nntp-Posting-Host: guitar.oit.unc.edu
  8. Organization: UNC Office of Information Technology
  9. References: <38385@cbmvax.commodore.com>
  10. Date: Thu, 7 Jan 1993 20:10:52 GMT
  11. Lines: 74
  12.  
  13. In article <38385@cbmvax.commodore.com> peter@cbmvax.commodore.com (Peter  
  14. Cherna) writes:
  15. >[...]Try this to handle messages from two ports:
  16. >
  17. >    struct MsgPort *mp1 = your first message port;
  18. >    struct MsgPort *mp2 = your second message port;
  19. >
  20. >    sigmask1 = 1 << mp1->mp_SigBit;
  21. >    sigmask2 = 1 << mp2->mp_SigBit;
  22. >
  23. >    while ( !done )
  24. >    {
  25. >        sigmask = Wait( sigmask1 | sigmask2 );
  26. >        if ( sigmask & sigmask1 )
  27. >        {
  28. >            while ( msg1 = GetMsg( mp1 ) )
  29. >            {
  30. >                handle messages from port 1 ...
  31. >            }
  32. >        }
  33. >        if ( sigmask & sigmask2 )
  34. >        {
  35. >            while ( msg2 = GetMsg( mp2 ) )
  36. >            {
  37. >                handle messages from port 2 ...
  38. >            }
  39. >        }
  40. >    }
  41.  
  42. I've used this dozens of times, but the other day I was getting
  43. messages from port 1 faster than I could process them so that
  44. I never got around to processing port 2's message, an act which
  45. would have made port 1's messages stop comming.  A busy dead-lock.
  46. Now I do something like this:
  47.  
  48.  while ( !done )
  49.  {
  50.      sigmask = Wait( sigmask1 | sigmask2 );
  51.      while ( (msg1 = GetMsg( mp1 )), (msg2 = GetMsg( mp2 )), (msg1 || msg2) )
  52.      {
  53.        if ( msg1 )
  54.               {
  55.                 handle a message from port 1 ...
  56.               }
  57.        if ( msg2 )
  58.               {
  59.                 handle a message from port 2 ...
  60.               }
  61.      }
  62.  }
  63.  
  64. This way both ports get roughly equal treatment, whereas in the example
  65. Peter gave port 1's messages must all be handled before port 2 even
  66. gets looked at.
  67.  
  68. Note that "while ( (msg1 = GetMsg( mp1 )) || (msg2 = GetMsg( mp2 )) )"
  69. wouldn't solve the problem because the second GetMsg() would not
  70. be called if the first GetMsg() actually got a message.
  71.  
  72. Some people might like this better:
  73.   do {
  74.         if (msg1 = GetMsg( mp1 ))
  75.            {
  76.              handle a message from port 1...
  77.            }
  78.         if (msg2 = GetMsg( mp2 ))
  79.            {
  80.              handle a message from port 2...
  81.            }
  82.      } while ( msg1 || msg2 );
  83. --
  84.  _/_/_/  _/     Todd_Lewis@unc.edu          You can lead a horse to 
  85.   _/    _/     utoddl@guitar.oit.unc.edu   Mohammad, but you can't make
  86.  _/    _/_/_/                             a mountain drink a mole hill.
  87.