Data race condition in ‘boost/thread/lock_types.hpp’

Open
#343 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp

Research direction

Start with boost/thread/lock_types.hpp, focusing on unique_lock, owns_lock(), and the line 451-452 unlock and is_locked update described in the report. Reproduce or inspect the Coverity 2020.03 finding and determine whether concurrent status checks can race with locking or unlocking. Done means establishing whether this is a false positive and documenting or resolving the issue with maintainer agreement.

Written by the indexing model from the issue text.

Description

Hi,
I've just run Coverity, version 2020.03, static analysis on a program using Boost v 1_75_0
It has highlighted several potential issues one of which I will describe here.

In lock_types.hpp the ‘unique_lock’ class contains a mutex and a Boolean guard, called ‘is_locked’, is checked, via the ‘owns_lock()’ method, prior to locking and unlocking the mutex and then set to true or false respectively. For example, on line 451 the mutex is unlocked and on line 452 the ‘is_locked’ is set to false. Another thread can at the same time call owns_lock() to check the locked status and potentially get wrong answer.
This, to me and the Coverity static analysis, creates a data race condition. Is that a false positive in the static analysis tool? What am I missing?

Thanks,
Dimitar

Dominant language
C++
Stars
213
Forks
171
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/thread

All issues in boostorg/thread

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.