Opened 4 years ago

Closed 4 years ago

#16644 closed defect (fixed)

Unpredictable scheduling behavior of threads

Reported by: cypherpunks Owned by:
Priority: Low Milestone: Tor: 0.2.7.x-final
Component: Core Tor/Tor Version: Tor: 0.2.6.3-alpha
Severity: Keywords: 026-backport
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

The POSIX standard states

The pthread_cond_broadcast() or pthread_cond_signal() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits; however, if predictable scheduling behavior is required, then that mutex shall be locked by the thread calling pthread_cond_broadcast() or pthread_cond_signal().

The highlighted recommendation isn't followed in by some thread pool functions which release the mutex before unblocking the threads. The issue was found using Helgrind (a Valgrind tool) which gave the warning Thread #1: pthread_cond_{signal,broadcast}: dubious: associated lock is not held by any thread

It is worth mentioning that the thread tests do follow the recommendation.

Child Tickets

Attachments (1)

0001-Switch-order-of-unblocking-threads-and-releasing-the.patch (1.7 KB) - added by cypherpunks 4 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 4 years ago by cypherpunks

Status: newneeds_review

The patch includes a changes file and was tested by running a patched Tor through make check, make test-network and make test-stem.

comment:2 Changed 4 years ago by nickm

Milestone: Tor: 0.2.7.x-final

LGTM; I think this one should go into 0.2.7.3-alpha.

comment:3 Changed 4 years ago by nickm

Keywords: 026-backport added
Milestone: Tor: 0.2.7.x-finalTor: 0.2.6.x-final

Merged; marking for possible backport.

comment:4 Changed 4 years ago by nickm

Milestone: Tor: 0.2.6.x-finalTor: 0.2.7.x-final
Resolution: fixed
Status: needs_reviewclosed

Marking as fixed-in-0.2.7. Though this casuses "unpredictable scheduling" in 0.2.6, it causes no problems as far as anybody has noticed.

Note: See TracTickets for help on using tickets.