void* foo(void*) { pA = new A(); B ob;

pthread_cleanup_push(reinterpret_cast<fp*>(thread_specific_destroy),pA); pthread_cleanup_pop(1);

ob.~B(); // potential problem when the thread is canceled. pthread_exit(0);

return 0;

}

int main() {

//A oa; exit(0);

//dtor for oa won’t be called if line above is uncommented. pthread_t thread_id;

for (int i = 0; i < 3; i++)

pthread_create(&thread_id, 0, &foo, 0); pthread_join(thread_id, 0);

}

NOTE: vector::clear does not free all of the memory. The storage is put back into a free pool for that one container.

This does not happen if a thread is canceled. In such cases, use thread specific data or thread local storage support along with pthread_cleanup_[pushpop] utilities.

pthread_cancel is not supported.

Function Scoping

Theset_terminate, set_unexpected, and set_new_handler, functions apply to all threads in the process. For information on specific functions, refer to the appropriate library documentation.

Performance Options

You can use the-D__HPACC_FIXED_REFCNT_MUTEXflag to reduce the amount of space used for string mutexes and thereby increase performance when using either -AAor -APstrings. Instead of having one mutex per string, there will be a fixed array of mutexes shared among all strings. This feature requires C++ runtime version A.05.61 or newer. For additional information refer to the -mtoption.

The number of string mutexes defaults to 64 and can be configured by:

export aCC_MUTEX_ARRAY_SIZE=##

You can mix code compiled with and without -D__HPACC_FIXED_REFCNT_MUTEX.

Parallel Programming Using OpenMP

OpenMP is an industry-standard parallel programming model that implements a fork-join model of parallel execution. The HP C++ OpenMP pragmas are based on the OpenMP Standard for C/C++, version 2.5.

To view the details about the standard and details about usage, syntax and values, please go to http://www.openmp.org/drupal/node/view/8.

OpenMP Implementation

This section summarizes some of the OpenMP directives behavior that are described as implementation-dependent in the OpenMP v2.5 API. Each behavior is cross-referenced back to its description in the OpenMP v2.5 main specification. HP, in conformance with the OpenMP v2.5 API, define and document the following behavior.

Due to resource constraints, it is not possible for an implementation to document the maximum number of threads that can be created successfully during a program’s execution. This number is dependent upon the load on the system, the amount of memory allocated by the program, and the amount of implementation dependent stack space allocated to each thread. For a 32

Function Scoping 167

Page 167
Image 167
HP C/aC++ for PA-RISC Software manual Function Scoping, Parallel Programming Using OpenMP, OpenMP Implementation