Libthreadar  1.0.1
 All Classes Namespaces Files Functions Macros
barrier.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // libthreadar - is a library providing several C++ classes to work with threads
3 // Copyright (C) 2014-2015 Denis Corbin
4 //
5 // This file is part of libthreadar
6 //
7 // libthreadar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // libhtreadar is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with libthreadar. If not, see <http://www.gnu.org/licenses/>
19 //
20 //----
21 // to contact the author: dar.linux@free.fr
22 /*********************************************************************/
23 
24 #ifndef LIBTHREADAR_BARRIER_HPP
25 #define LIBTHREADAR_BARRIER_HPP
26 
29 
30 #include "config.h"
31 
32  // C system headers
33 extern "C"
34 {
35 #if HAVE_PTHREAD_H
36 #include <pthread.h>
37 #endif
38 }
39  // C++ standard headers
40 
41 
42  // libthreadar headers
43 
44 
45 
46 namespace libthreadar
47 {
49 
57  class barrier
58  {
59  public:
61 
63  barrier(unsigned int num);
64 
65  // no copy constructor (made private)
66 
67  // no assignment operator (made private)
68 
70 
72  ~barrier();
73 
75 
78  void wait();
79 
80  private:
81  barrier(const barrier & ref) { throw THREADAR_BUG; };
82  const barrier & operator = (const barrier & ref) { throw THREADAR_BUG; };
83 
84  pthread_barrier_t bar;
85  };
86 
87 } // end of namespace
88 
89 #endif
#define THREADAR_BUG
Macro used to throw an exception_bug when execution reach that statement.
Definition: exceptions.hpp:145
void wait()
suspend the calling thread waiting for other up to 'num' other thread to call wait too ...
~barrier()
The destructor.
barrier(unsigned int num)
The constructor.
the class barrier allows several threads to synchronize between them
Definition: barrier.hpp:57
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition: barrier.hpp:46