data race detection confusion
I've got the following code in fraggen.cc. The first section is some global variables, which ought to be initialized before main() begins.
193 // Access to this queue must always be protected by the associated mutex.
194 // The condition variable is used to wake up any process which is waiting
195 // for the queue to become non-empty.
196 queue< JobUpdateRequest *, list<JobUpdateRequest *> > job_update_queue;
197 pthread_mutex_t job_update_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
198 pthread_cond_t job_update_outstanding = PTHREAD_COND_INITIALIZER;
1042 // wait on a queue of job read/refresh requests, and process them as they come in
1043 while (! halt_signal_was_received ());
1044{
1045pthread_mutex_lock (&job_update_queue_mutex);
1046while (job_update_queue.empty ())
1047 {
1048 pthread_cond_wait (&job_update_outstanding, &job_update_queue_mutex);
1049 }
1050JobUpdateRequest *job_update_request_ptr = job_update_queue.front ();
1051job_update_queue.pop ();
1052pthread_mutex_unlock (&job_update_queue_mutex);
1053process_job_update_request (job_update_request_ptr);
1054delete job_update_request_ptr;
1055}
Now I run this under the Data Race Detection Tool, and it reports:
Race #2, Vaddr: 0x1f7320
Access 1: Read, job_status_reader_thread_main + 0x000001B8,
line 1046 in "fraggen.cc"
Access 2: Write, std::_List_base<JobUpdateRequest*,std::allocator><JobUpdateRequest*> ; >::clear() + 0x0000022C,
line 76 in alternate source context "_list.c"
Total Traces: 1
Trace 1
Access 1: Read
job_status_reader_thread_main + 0x000001B8, line 1046 in "fraggen.cc"
Access 2: Write
std::_List_base<JobUpdateRequest*,std::allocator><JobUpdateRequest*> ; >::clear() + 0x0000022C, line 76 in alternate source context "_list.c"
__SLIP.FINAL__B + 0x0000003C, line 196 in "fraggen.cc"
_exithandle + 0x0000003C
exit + 0x00000004
_start + 0x00000110
There are a few issues with this:
(1) _list.c appears to be from the stlport library, which I'm using. Somewhat to my amazement, the Sun Studio documentation is very clear about which version of this library is used by Sun Studio 11: version 4.5.3. Is that the same version still in use by Studio Express?
(2) How is it that I get a race condition between a piece of code (the queue constructor) that ought to be executed before main() begins, and a piece of code (a call to the queue's empty() function) that is only executed after main() begins? If this is an example of a false positive because the constructor is not protected by a mutex, then I would suggest that DRDT be extended to special-case a recognition that such pre-main() initialization of global variables cannot cause race conditions (there being only one thread living at that point).
(3) Why is it that when I run "collect" to gather race-detection data for this program, it eventually dumps core, whereas if I run exactly the same copy of my program but not under "collect", no such core file appears?
Message was edited by:
herteg

