Bug 463991 - Potential false positive (destruction of condition variable being waited upon) with std::condition_variable
Summary: Potential false positive (destruction of condition variable being waited upon...
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: helgrind (show other bugs)
Version: 3.20 GIT
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-08 05:18 UTC by pbs3141
Modified: 2023-01-09 17:30 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Code snippet copied from stackoverflow and fixed to compile (929 bytes, text/x-c++src)
2023-01-08 05:18 UTC, pbs3141
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pbs3141 2023-01-08 05:18:32 UTC
Created attachment 155099 [details]
Code snippet copied from stackoverflow and fixed to compile

SUMMARY

Destroying a std::condition_variable after calling notify_all() results in a helgrind warning "pthread_cond_destroy: destruction of condition variable being waited upon", even though this behaviour is apparently allowed by the C++ spec (http://en.cppreference.com/w/cpp/thread/condition_variable/~condition_variable).

See this stackoverflow question (https://stackoverflow.com/questions/48093715/destruction-of-condition-variable-randomly-loses-notification) for a full discussion, although only the posts by the OP and the user mevets are worth reading. Ultimately it seems the program is correct, although the discussion is contentious which is why I've included "potential" in the bug report title.

STEPS TO REPRODUCE

Run the snippet in the stackoverflow question (also attached) under helgrind.

OBSERVED RESULT

The error message

==71731== Thread #1: pthread_cond_destroy: destruction of condition variable being waited upon
==71731==    at 0x484AA83: ??? (in /usr/libexec/valgrind/vgpreload_helgrind-amd64-linux.so)
==71731==    by 0x4959E3D: __gthread_cond_destroy (gthr-default.h:885)
==71731==    by 0x4959E3D: ~__condvar (std_mutex.h:141)
==71731==    by 0x4959E3D: std::condition_variable::~condition_variable() (condition_variable.cc:36)
==71731==    by 0x1098DB: notify_on_delete::~notify_on_delete() (in a.out)
==71731==    by 0x109381: main (in a.out)

EXPECTED RESULT

No error messages.

SOFTWARE/OS VERSIONS

valgrind-3.20.0.GIT

Target: x86_64-pc-linux-gnu
gcc version 12.2.0 (GCC)
Comment 1 Paul Floyd 2023-01-09 09:06:48 UTC
"only the posts by the OP and the user mevets are worth reading" SO in a nutshell.
Comment 2 Paul Floyd 2023-01-09 17:30:03 UTC
This also seems to apply to DRD.