Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No amount of genius can overcome a preoccupation with detail.


devel / comp.lang.c++ / Re: std::unique_lock - Cannot lock twice?

SubjectAuthor
* Re: std::unique_lock - Cannot lock twice?Bonita Montero
`- Re: std::unique_lock - Cannot lock twice?Chris M. Thomasson

1
Re: std::unique_lock - Cannot lock twice?

<u6fggs$fhsc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=393&group=comp.lang.c%2B%2B#393

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: std::unique_lock - Cannot lock twice?
Date: Thu, 15 Jun 2023 19:07:41 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <u6fggs$fhsc$1@dont-email.me>
References: <8d0c2e10-4c87-4b1e-9800-67be6a3e0e35@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 15 Jun 2023 17:07:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="959c7d2278d53cc6c55fcb40db86c57a";
logging-data="509836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ypKbAnVXZzN9sAnrSl40LVC5Fa+0um98="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:vjeBe//RUV8CGFLhRQMIMMtiovM=
Content-Language: de-DE
In-Reply-To: <8d0c2e10-4c87-4b1e-9800-67be6a3e0e35@googlegroups.com>
 by: Bonita Montero - Thu, 15 Jun 2023 17:07 UTC

Am 08.03.2017 um 23:57 schrieb Christopher:
> 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();
> }
>
>
> This throws on the second attempt to lock.
> I thought the difference between unique lock and lock guard was that unique lock allowed manually locking and unlocking. We cannot lock it twice?

Aside from that you've to use unlock() and not release():
unlock() releases ownership so you are unable to re-lock
the mutex.

Re: std::unique_lock - Cannot lock twice?

<u6gh40$n7lu$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=401&group=comp.lang.c%2B%2B#401

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: std::unique_lock - Cannot lock twice?
Date: Thu, 15 Jun 2023 19:23:59 -0700
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <u6gh40$n7lu$3@dont-email.me>
References: <8d0c2e10-4c87-4b1e-9800-67be6a3e0e35@googlegroups.com>
<u6fggs$fhsc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 16 Jun 2023 02:24:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0da7e8b9d89a27cb9249e4ee45fca245";
logging-data="761534"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IBmAWW5p2vv9X3hW95kLdKR8K3J+agIw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:mty9aVSqDCbRygeTo10OUvyFr1c=
Content-Language: en-US
In-Reply-To: <u6fggs$fhsc$1@dont-email.me>
 by: Chris M. Thomasson - Fri, 16 Jun 2023 02:23 UTC

On 6/15/2023 10:07 AM, Bonita Montero wrote:
> Am 08.03.2017 um 23:57 schrieb Christopher:
>> 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();
>> }
>>
>>
>> This throws on the second attempt to lock.
>> I thought the difference between unique lock and lock guard was that
>> unique lock allowed manually locking and unlocking. We cannot lock it
>> twice?
>
> Aside from that you've to use unlock() and not release():
> unlock() releases ownership so you are unable to re-lock
> the mutex.
>

what about a hand off algorithm. Pass the buck?

A has a reference, hands off to B, now A is null. B is current in a
single atomic operation. On and on...

https://youtu.be/oRrlRbGT-LU

;^)


devel / comp.lang.c++ / Re: std::unique_lock - Cannot lock twice?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor