Contents

Name
Description
Synopsys
Restrictions
Members
Construction/Destruction
Assignment
Critical Sections
Author
Copyright & License
Version
Downloading
Environment

hcritsec - C++ class for Critical Sections in programs

hcritsec can be used to define a critical section in a program. It can be used in a recursive way. So functions that are nested can call the ''enter'' and ''leave'' functions recursively (see section Synopsys).

A critical section class is typically shared between threads, or is part of an object or variable that is shared between threads.

It can be used to gain exclusive access to shared resources or variables.

        (...)

        void thread_class::calc(int *t)
        {
                S->enter();
                *t+=1;
                S->leave();
        }

        void thread_class::run(void)
        {
                for(i=0;i<100000;i++) {
                        S->enter();
                        calc(t);
                        S->leave();
                }
        }

        (...)

        int main()
        {
                hcrisec S;
                int     t=0;
                thread_class t1(&S,&t),t2(&s,&t)

                        t1.start();
                        t2.start();

                        thread_class::join(t1,t2);

                return 0;
        }
  • You may not copy an object of class critsec. Allways use a pointer to share the object between threads.

  • If hcritsec throws a fatal error, this will allways be of type std::string.

Constructor for hcritsec. Constructs and initializes a hcritsec object.

Throws a fatal error because a hcritsec object may not be copied.

Destructor for hcritsec. Destructs a hcritsec objects. Throws a fatal error, if the critical section is deleted while in use.

Throws a fatal error because a hcritsec object may not be copied.

Enters a critical section.

Leaves a critical section. If a critical section is left more times then it has been entered, it throws a fatal error.

Hans Oesterholt-Dijkema <hdnews -at- gawab.com>

(c) 2000 - 2004 Hans Oesterholt-Dijkema.
hcritsec has been released under the Elemental Programming Artistic License.

This documentation is part of package ''critsec'', v0.20.

Latest releases of all packages can be found here.

hcritsec is part of the Elemental Programming Effort.

page hits: 973, last edit: