Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor III
5 Views

TBB 3 update 4 terminates on startup

Hi,
The latest release doesn't work with GCC 4.1.0 on Linux, it terminates on firsttask_scheduler_init construction. The problem is that the compiler incorrectly compiles all calls toatomic_do_once, as they written in a few places - it simply doesn't call once initializer. In particular, the crash is caused by not initializingtheNumProcs inAvailableHwConcurrency() on Linux (see tbb_misc_ex.cpp:121) and as a consequence - an attempt to allocate an array of -1 elements at private_server.cpp:318.
I've found 3 places whereatomic_do_once is used improperly. The following simple change fixes the problem:


diff -ur --strip-trailing-cr tbb30_127oss/src/tbb/condition_variable.cpp TBB/src/tbb/condition_variable.cpp
--- tbb30_127oss/src/tbb/condition_variable.cpp	2010-12-08 14:29:02.000000000 +0300
+++ TBB/src/tbb/condition_variable.cpp	2010-12-09 19:36:34.604404300 +0300
@@ -169,7 +169,8 @@
 
 void internal_initialize_condition_variable( condvar_impl_t& cv )
 {
-    atomic_do_once( init_condvar_module, condvar_api_state );
+    typedef void (*init_condvar_module_t)();
+    atomic_do_once( (init_condvar_module_t)&init_condvar_module, condvar_api_state );
     __TBB_init_condvar( &cv.cv_native );
 }
 
diff -ur --strip-trailing-cr tbb30_127oss/src/tbb/tbb_misc_ex.cpp TBB/src/tbb/tbb_misc_ex.cpp
--- tbb30_127oss/src/tbb/tbb_misc_ex.cpp	2010-12-08 14:29:02.000000000 +0300
+++ TBB/src/tbb/tbb_misc_ex.cpp	2010-12-10 10:11:07.432904100 +0300
@@ -119,7 +119,8 @@
 }
 
 int AvailableHwConcurrency() {
-    atomic_do_once( initialize_hardware_concurrency_info, hardware_concurrency_info );
+    typedef void (*initialize_hardware_concurrency_info_t)();
+    atomic_do_once( (initialize_hardware_concurrency_info_t)&initialize_hardware_concurrency_info, hardware_concurrency_info );
     return theNumProcs;
 }
 
@@ -225,7 +226,8 @@
 }
 
 int AvailableHwConcurrency() {
-    atomic_do_once( initialize_hardware_concurrency_info, hardware_concurrency_info );
+    typedef void (*initialize_hardware_concurrency_info_t) ();
+    atomic_do_once( (initialize_hardware_concurrency_info_t)&initialize_hardware_concurrency_info, hardware_concurrency_info );
     return theProcessorGroups[ProcessorGroupInfo::NumGroups - 1].numProcsRunningTotal;
 }
 

As a side note, I'll add that without the modification the code does not compile with MSVC 7.1. I know this compiler is not supported anymore, but the change also fixes the problem for this compiler.

0 Kudos
2 Replies
Highlighted
5 Views

Andy, thanks for letting us know about the issue and providing the patch.

Would it work with both the compilers if typedefs are omitted and we just explicitly take the address of routines before passing to atomic_do_once?

0 Kudos
Highlighted
New Contributor III
5 Views

Yes, this seems to work for both compilers.
0 Kudos