Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
task_scheduler_init.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
18 
19 #if !defined(__TBB_show_deprecation_message_task_scheduler_init_H) && defined(__TBB_show_deprecated_header_message)
20 #define __TBB_show_deprecation_message_task_scheduler_init_H
21 #pragma message("TBB Warning: tbb/task_scheduler_init.h is deprecated. For details, please see Deprecated Features appendix in the TBB reference manual.")
22 #endif
23 
24 #if defined(__TBB_show_deprecated_header_message)
25 #undef __TBB_show_deprecated_header_message
26 #endif
27 
28 #ifndef __TBB_task_scheduler_init_H
29 #define __TBB_task_scheduler_init_H
30 
31 #define __TBB_task_scheduler_init_H_include_area
33 
34 #include "tbb_stddef.h"
35 #include "limits.h"
36 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
37 #include <new> // nothrow_t
38 #endif
39 
40 namespace tbb {
41 
42 typedef std::size_t stack_size_type;
43 
45 namespace internal {
47 
48  class scheduler;
49 } // namespace internal
51 
53 
68  propagation_mode_exact = 1u,
69  propagation_mode_captured = 2u,
70  propagation_mode_mask = propagation_mode_exact | propagation_mode_captured
71  };
72 
75 
76  bool internal_terminate( bool blocking );
77 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
78  bool __TBB_EXPORTED_METHOD internal_blocking_terminate( bool throwing );
79 #endif
80 public:
81 
83  static const int automatic = -1;
84 
86  static const int deferred = -2;
87 
89 
100  void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
101 
103 
104  void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
105 
107  void __TBB_EXPORTED_METHOD terminate();
108 
109 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
110 #if TBB_USE_EXCEPTIONS
111  void blocking_terminate() {
113  internal_blocking_terminate( /*throwing=*/true );
114  }
115 #endif
116  bool blocking_terminate(const std::nothrow_t&) __TBB_NOEXCEPT(true) {
118  return internal_blocking_terminate( /*throwing=*/false );
119  }
120 #endif // __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
121 
123  task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL)
124  {
125  // Two lowest order bits of the stack size argument may be taken to communicate
126  // default exception propagation mode of the client to be used when the
127  // client manually creates tasks in the master thread and does not use
128  // explicit task group context object. This is necessary because newer
129  // TBB binaries with exact propagation enabled by default may be used
130  // by older clients that expect tbb::captured_exception wrapper.
131  // All zeros mean old client - no preference.
132  __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
133 #if TBB_USE_EXCEPTIONS
134  thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
135 #endif /* TBB_USE_EXCEPTIONS */
136  initialize( number_of_threads, thread_stack_size );
137  }
138 
141  if( my_scheduler )
142  terminate();
143  internal::poison_pointer( my_scheduler );
144  }
146 
163  static int __TBB_EXPORTED_FUNC default_num_threads ();
164 
166  bool is_active() const { return my_scheduler != NULL; }
167 };
168 
169 } // namespace tbb
170 
172 #undef __TBB_task_scheduler_init_H_include_area
173 
174 #endif /* __TBB_task_scheduler_init_H */
#define TBB_USE_CAPTURED_EXCEPTION
Definition: tbb_config.h:492
#define __TBB_DEPRECATED_IN_VERBOSE_MODE
Definition: tbb_config.h:647
std::size_t stack_size_type
task_scheduler_init(int number_of_threads=automatic, stack_size_type thread_stack_size=0)
Shorthand for default constructor followed by call to initialize(number_of_threads).
#define __TBB_NOEXCEPT(expression)
Definition: tbb_stddef.h:110
~task_scheduler_init()
Destroy scheduler for this thread if thread has no other live task_scheduler_inits.
#define __TBB_EXPORTED_FUNC
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:330
Class delimiting the scope of task scheduler activity.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
internal::scheduler * my_scheduler
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305
bool is_active() const
Returns true if scheduler is active (initialized); false otherwise.
The graph class.

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.