On 6/8/2023 12:11 PM, Chris M. Thomasson wrote:
> On 6/8/2023 7:05 AM, nan dhan wrote:
>> On Thursday, March 9, 2017 at 1:10:08 AM UTC+1, Chris Vine wrote:
>>> On Wed, 8 Mar 2017 14:57:09 -0800 (PST)
>>> Christopher <
christo...@gmail.com> wrote:
>>>> I debugged an application to the following scenario:
>>>>
>>>>
>>>> #include <mutex>
>>>>
>>>> std::mutex g_mutex;
>>>>
>>>> int main()
>>>> {
>>>>
>>>> std::unique_lock<std::mutex> lock(g_mutex);
>
>
> _________________________
>>>> lock.release();
>>>> lock.lock();
>>>> lock.release();
>>>> }
> _________________________
>
> lock.unlock();
> lock.lock();
> lock.unlock();
[...]
No! Shit man. Wait a minute. Self SLAP!!!!!
std::unique_lock<std::mutex> lock(g_mutex); --> LOCK
lock.unlock(); --> UNLOCK
lock.lock(); --> LOCK
lock.unlock(); --> UNLOCK
You need another lock _before_ that dtor of:
std::unique_lock<std::mutex> lock(g_mutex);
automatically unlocks! God damn it!