Opened 3 years ago

Last modified 22 months ago

#18308 accepted defect

Use a better pattern for "create mutex if not already initialized"

Reported by: cypherpunks Owned by: nickm
Priority: Medium Milestone: Tor: unspecified
Component: Core Tor/Tor Version:
Severity: Normal Keywords: threading, standards-compliance, posix, win32
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Tor relies on double checked locking for various threading initializations. Double checked locking is not guaranteed to work.

For Posix: 4.11, Memory Synchronization:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html

Applications shall ensure that access to any memory location by more than one thread of control (threads or processes) is restricted such that no thread of control can read or modify a memory location while another thread of control may be modifying it.

Race conditions:
compat_pthreads.c:threads_initialized

log.c:log_mutex_initialized

Mutex static initialization is supported by pthreads via PTHREAD_MUTEX_INITIALIZER.

Child Tickets

Change History (7)

comment:1 Changed 3 years ago by nickm

Milestone: Tor: 0.2.9.x-final
Owner: set to nickm
Status: newaccepted

comment:2 Changed 3 years ago by nickm

Keywords: nickm-deferred-20160905 added
Milestone: Tor: 0.2.9.x-finalTor: 0.2.???

Defer some of my own tickets to 0.2.???

comment:3 Changed 2 years ago by teor

Milestone: Tor: 0.2.???Tor: 0.3.???

Milestone renamed

comment:4 Changed 2 years ago by nickm

Keywords: tor-03-unspecified-201612 added
Milestone: Tor: 0.3.???Tor: unspecified

Finally admitting that 0.3.??? was a euphemism for Tor: unspecified all along.

comment:5 Changed 2 years ago by nickm

Keywords: tor-03-unspecified-201612 removed

Remove an old triaging keyword.

comment:6 Changed 2 years ago by nickm

Keywords: nickm-deferred-20160905 removed

comment:7 Changed 22 months ago by nickm

Keywords: threading standards-compliance posix win32 added
Summary: Tor threading brokenUse a better pattern for "create mutex if not already initialized"

Not too hard to do right on posix, but downright unrealistic with CRITICAL_SECTION values on windows. Might need a hybrid approach for static mutexes.

Note: See TracTickets for help on using tickets.