bugThe libunwind project - Bugs: bug #42677, double-checked locking on...

 
 

bug #42677: double-checked locking on tdep_init_done triggers ThreadSanitizer error

Submitted by:  None
Submitted on:  Thu 03 Jul 2014 10:10:25 PM UTC  
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 03 Jul 2014 10:10:25 PM UTC, original submission:

unw_init_local looks at the tdep_init_done variable outside any lock and calls tdep_init() if it is not already initted. This function then uses a mutex to prevent double initialization if two threads call it at the same time.

This isn't quite guaranteed to be safe since tdep_init_done isn't declared to be volatile, and thus the compiler may choose to reorder the "tdep_init_done = 1" line with other parts of the initialization. (x86 is a TSO memory model, but the compiler's still free to reorder things in the absense of a barrier).

I noticed this error because ThreadSanitizer flagged an unsafe read from unw_local_addr_space.

Rather than trying to implement the "init once" semantics anew, it's probably better to just use pthread_once(), which has the added bonus that tools like ThreadSanitizer know how to handle it.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

 

 

No changes have been made to this item

Back to the top


Powered by Savane 3.3