Contained WithinFind More DocumentationFeatured Support Resources | Descargar este libro en PDF (965 KB)
Appendix A Thread Analyzer User APIThe Thread Analyzer can recognize most standard synchronization APIs and constructs provided by OpenMP directives, POSIX threads, and Solaris threads. However, the tool cannot recognize user-defined synchronizations, and may report false positive data-races if you employ such synchronizations. For example, the tool cannot recognize spin locking that is implemented through hand-coded assembly-language code. If your code includes user-defined synchronizations, insert the user APIs supported by the Thread Analyzer into the program to identify those synchronizations. This identification allows the Thread Analyzer to recognize the synchronizations and reduce the number of false positives. The user APIs are listed below: A.1 The Thread-Analyzer's User-APIsTable A–1 Thread-Analyzer User-APIs
A C/C++ version and a Fortran version of the APIs are provided. Each API call takes a single argument id, whose value should uniquely identify the synchronization object. In the C/C++ version of the APIs, the type of the argument is uintptr_t, which is 4 bytes long in 32-bit mode and 8 bytes long in 64-bit mode. You need to add #include <tha_interface.h> to your C/C++ source file when calling any of the APIs. In the Fortran version of the APIs, the type of the argument is integer of kind tha_sobj_kind which is 8-bytes long in both 32-bit and 64–bit mode. You need to add include "tha_finterface.h" to your Fortran source file when calling any of the APIs. To uniquely identify a synchronization object, the argument id should have a different value for each different synchronization object. One way to do this is to use the value of the address of the synchronization object as the ID. The following code example shows how to use the API to avoid a false positive data-race: # include <tha_interface.h>
...
/* Initially, the ready_flag value is zero */
...
/* Thread 1: Producer */
100 data = ...
101 pthread_mutex_lock (&mutex);
tha_notify_sync_post_begin ((uintptr_t) &ready_flag);
102 ready_flag = 1;
tha_notify_sync_post_end ((uintptr_t) &ready_flag);
103 pthread_cond_signal (&cond);
104 pthread_mutex_unlock (&mutex);
/* Thread 2: Consumer */
200 pthread_mutex_lock (&mutex);
tha_notify_sync_wait_begin ((uintptr_t) &ready_flag);
201 while (!ready_flag) {
202 pthread_cond_wait (&cond, &mutex);
203 }
tha_notify_sync_wait_end ((uintptr_t) &ready_flag);
204 pthread_mutex_unlock (&mutex);
205 ... = data;
For more information on the user APIs, see the libtha.3 man page. A.2 Other Recognized APIsThe following sections detail the threading APIs which the Thread Analyzer recognizes: A.2.1 POSIX Thread APIs
A.2.2 Solaris Thread APIs
A.2.3 Memory-Allocation APIs
A.2.4 OpenMP APIsSee the Sun Studio 12: OpenMP API User’s Guide for more information. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||