1 //===-------------------- test_exception_storage.cpp ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "../src/config.h"
15 #if !LIBCXXABI_SINGLE_THREADED
20 #include "../src/cxa_exception.hpp"
22 typedef __cxxabiv1::__cxa_eh_globals globals_t ;
24 void *thread_code (void *parm) {
25 size_t *result = (size_t *) parm;
26 globals_t *glob1, *glob2;
28 glob1 = __cxxabiv1::__cxa_get_globals ();
30 std::cerr << "Got null result from __cxa_get_globals" << std::endl;
32 glob2 = __cxxabiv1::__cxa_get_globals_fast ();
34 std::cerr << "Got different globals!" << std::endl;
36 *result = (size_t) glob1;
41 #if !LIBCXXABI_SINGLE_THREADED
43 size_t thread_globals [ NUMTHREADS ] = { 0 };
44 pthread_t threads [ NUMTHREADS ];
47 void print_sizes ( size_t *first, size_t *last ) {
48 std::cout << "{ " << std::hex;
49 for ( size_t *iter = first; iter != last; ++iter )
50 std::cout << *iter << " ";
51 std::cout << "}" << std::dec << std::endl;
54 int main ( int argc, char *argv [] ) {
57 #if LIBCXXABI_SINGLE_THREADED
58 size_t thread_globals;
59 retVal = thread_code(&thread_globals) != 0;
61 // Make the threads, let them run, and wait for them to finish
62 for ( int i = 0; i < NUMTHREADS; ++i )
63 pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
64 for ( int i = 0; i < NUMTHREADS; ++i )
65 pthread_join ( threads [ i ], NULL );
67 for ( int i = 0; i < NUMTHREADS; ++i )
68 if ( 0 == thread_globals [ i ] ) {
69 std::cerr << "Thread #" << i << " had a zero global" << std::endl;
73 // print_sizes ( thread_globals, thread_globals + NUMTHREADS );
74 std::sort ( thread_globals, thread_globals + NUMTHREADS );
75 for ( int i = 1; i < NUMTHREADS; ++i )
76 if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) {
77 std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl;
80 // print_sizes ( thread_globals, thread_globals + NUMTHREADS );