home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / icritsec.hp_ / ICRITSEC.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  2.2 KB  |  75 lines

  1. /*==============================================================================
  2.  Module Name: icritsec.hpp
  3.  
  4.  Description: 
  5.    "Critical section" class interface specification.
  6.  
  7.  Copyright: (C) Copyright IBM Corporation 1992
  8.             All Rights Reserved
  9.             Licensed Materials = Property of IBM
  10.  
  11.  Usage:
  12.    This file is #include-d in programs needing use of OS/2 "critical
  13.    sections."
  14.  
  15.  Notes:
  16.  
  17.  Related Topics:
  18.  
  19.  History:
  20.    flag yymmdd who description
  21.    ---- ------ --- -----------------------------------------------------------
  22.         920901 law Initial (from IThread work)
  23. ==============================================================================*/
  24. #if !defined( _ICRITSEC_ )
  25. #define _ICRITSEC_
  26.  
  27. /*------------------------------------------------------------------------------
  28.  Class Name: ICritSec
  29.  
  30.  Description:
  31.    Critical section class.
  32.  
  33.  Usage:
  34.    Instances of this class are declared within blocks considered to be
  35.    "critical sections."  Such blocks usually manipulate static data and
  36.    need to do so without interruption from code executing in other
  37.    threads.
  38.  
  39.    Instances of this class guarantee that no other thread in the current
  40.    process will execute between the object's construction and 
  41.    destruction.
  42.  
  43.    Typically, code that must execute without interruption by other
  44.    threads is partitioned into a separate "block" (delimited by {}).
  45.    Within that block is declared an instance of this class.  For example:
  46.    :xmp.
  47.    {
  48.    ICritSec lock;
  49.    // Manipulate static data without interruption...
  50.    }
  51.    :exmp.
  52.  
  53.  Notes:
  54.    1. Care must be taken to avoid dangerous actions during the duration
  55.       of the critical section.  Typically, system calls should be avoided.
  56.       If locks must be preserved beyond the scope of an ICritSec, semaphores
  57.       should be used.
  58.    2. Please read the OS/2 Programming Reference information on
  59.       DosEnterCritSec/DosExitCritSec.
  60.  
  61.  Related Topics:
  62. ------------------------------------------------------------------------------*/
  63. class ICritSec {
  64. public:
  65. // Ctor enters critical section.
  66. ICritSec();
  67. // Dtor exits.
  68. ~ICritSec();
  69. // Static count for diagnostics purposes.
  70. static unsigned long
  71.   count;
  72. };
  73.  
  74. #endif /* _ICRITSEC_ */
  75.