220 17639 <9A3E0561DCF227429F72080EA81ADBC95084454075@TUS1XCHEVSPIN42.SYMC.SYMANTEC.COM> article
Path: news.gmane.org!not-for-mail
From: Michael Spertus <mike_spertus@symantec.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: RE: Comments on N4470 "Variadic lock_guard"
Date: Thu, 30 Apr 2015 14:12:35 -0700
Lines: 466
Approved: news@gmane.org
Message-ID: <9A3E0561DCF227429F72080EA81ADBC95084454075@TUS1XCHEVSPIN42.SYMC.SYMANTEC.COM>
References: <f3536471-72fe-4077-ae82-d508cd41607a@isocpp.org>
 <9A3E0561DCF227429F72080EA81ADBC95084453ECA@TUS1XCHEVSPIN42.SYMC.SYMANTEC.COM>
 <5199fc13-1dae-4a11-907b-159d98487c9d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
	boundary="_000_9A3E0561DCF227429F72080EA81ADBC95084454075TUS1XCHEVSPIN_"
X-Trace: ger.gmane.org 1430428386 32749 80.91.229.3 (30 Apr 2015 21:13:06 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 30 Apr 2015 21:13:06 +0000 (UTC)
To: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>, "std-proposals@isocpp.org"
	<std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDRKVPVDWYNBBSNVRKVAKGQEVXQID7Q@isocpp.org Thu Apr 30 23:12:46 2015
Return-path: <std-proposals+bncBDRKVPVDWYNBBSNVRKVAKGQEVXQID7Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f198.google.com ([209.85.212.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDRKVPVDWYNBBSNVRKVAKGQEVXQID7Q@isocpp.org>)
	id 1YnvlC-0001LW-78
	for gclcip-std-proposals@m.gmane.org; Thu, 30 Apr 2015 23:12:42 +0200
Original-Received: by wicmx19 with SMTP id mx19sf9042829wic.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 30 Apr 2015 14:12:41 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:date:subject:thread-topic:thread-index
         :message-id:references:in-reply-to:accept-language:content-language
         :acceptlanguage:content-type:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=Sijft1BKa/GMTu4ww96fIMxkfBwRWaLMRUCMjR/+PYg=;
        b=Xd16F201OZB01aJ8RufrwMO80VARkaRCSOmTZUCwBEvKKO2azmbZwmrFGGaRYBYWWH
         kFfcjDeBV30/vuvq7gwe6Vi/m1c74svUfMk/Q7KZqi1L2xLromM4zJHcgO78dGV9Jg0F
         asKOckPB6CH5cG0+QBWQEsZLMWB6MB29R7CHcewvYC17x8VLFrT0aMWOyXibLE5YiFah
         axei3pEmd6KU1BWdfC2vCeczd24V5nTZPPktat4Dfq0927SqRAvbf/tpHjOquAN/qnJ4
         QBB28y/pnCl7k0wqGiD7BTfok26LC3IK7R 
X-Gm-Message-State: ALoCoQnwhiMqdlK841M2FULeNOs9GbNTnBbQkjw+nNFqtUTQX8/caZJdqpSl0NG2FBmVUKB1RQa6
X-Received: by 10.112.219.200 with SMTP id pq8mr4032714lbc.7.1430428361810;
        Thu, 30 Apr 2015 14:12:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.104.135 with SMTP id ge7ls230856wib.25.gmail; Thu, 30 Apr
 2015 14:12:40 -0700 (PDT)
X-Received: by 10.194.173.226 with SMTP id bn2mr12305192wjc.148.1430428360777;
        Thu, 30 Apr 2015 14:12:40 -0700 (PDT)
Original-Received: from ecl1mtaoutpex01.symantec.com (ecl1mtaoutpex01.symantec.com. [166.98.1.209])
        by mx.google.com with ESMTPS id y14si5426917wju.139.2015.04.30.14.12.40
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Thu, 30 Apr 2015 14:12:40 -0700 (PDT)
Received-SPF: pass (google.com: domain of mike_spertus@symantec.com designates 166.98.1.209 as permitted sender) client-ip=166.98.1.209;
X-AuditID: a66201d1-f79226d000006a45-a0-55429ac77e30
Original-Received: from ecl1mtahubpin01.ges.symantec.com (ecl1mtahubpin01.ges.symantec.com [10.48.69.201])
	by ecl1mtaoutpex01.symantec.com (Symantec Brightmail Gateway out) with SMTP id 62.1C.27205.7CA92455; Thu, 30 Apr 2015 21:12:39 +0000 (GMT)
Original-Received: from [155.64.220.139] (helo=TUS1XCHHUBPIN03.SYMC.SYMANTEC.COM)
	by ecl1mtahubpin01.ges.symantec.com with esmtp (Exim 4.76)
	(envelope-from <mike_spertus@symantec.com>)
	id 1Ynvl8-00007n-4W; Thu, 30 Apr 2015 21:12:38 +0000
Original-Received: from TUS1XCHEVSPIN42.SYMC.SYMANTEC.COM ([155.64.221.73]) by
 TUS1XCHHUBPIN03.SYMC.SYMANTEC.COM ([155.64.220.139]) with mapi; Thu, 30 Apr
 2015 14:12:40 -0700
Thread-Topic: Comments on N4470 "Variadic lock_guard"
Thread-Index: AdCDh/PH6yHK82OCSkWoBuF1/7z/GwAADDSg
In-Reply-To: <5199fc13-1dae-4a11-907b-159d98487c9d@isocpp.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
acceptlanguage: en-US
X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRmVeSWpSXmKPExsXCZeB6Uvf4LKdQg11XOSyerlzBYvH1epQD
	k8fOWXfZPSa+n8kSwBTFZZOSmpNZllqkb5fAlfFi6iSmghU9TBU/HjYxNzAuaWXqYuTkkBAw
	kdh48iwjhC0mceHeerYuRi4OIYF3jBIP+05COa8YJbbPms0C4axklDh9dAUrSAubgKHE5A/n
	WEBsEYF0iWUrloONYhFQlVjbO5kdxBYGWtHa+wOqxlRi4e6PzF2MHEC2kcTBk7ogJq9AlMTa
	XSEQ4w8xSqzfdRTsOk4BO4nORZOYQWxGoOu+n1oDFmcWEJe49WQ+1AcCEkv2nGeGsEUlXj7+
	xwpRLypxp309I0R9vsSKGbPA6nkFBCVOznzCMoFRdBaSUbOQlM1CUjYL6DxmAU2gk/QhShQl
	pnQ/ZIewNSRa58xlRxZfwMi+ilEmNTnHMLckMb+0pCC1wsBQr7gyNxEYe8l6yfm5mxiB8bcs
	ifHiDsYLh3UPMQpwMCrx8FZ3O4UKsSaWAVUC/c/BrCTCKzUDKMSbklhZlVqUH19UmpNafIhR
	moNFSZz3UadoqJBAemJJanZqakFqEUyWiYNTqoGxaPLSl/NXJGQd55R5tGC21al+v12+ie3/
	0yT5FjGcjZ/hZbHa64bxbtmlFuILF+XumRmSd3TZt52y7a6uNx19BR/KHduZXLXeb1XwhPUv
	ShzMze7c0Jp9v6DgSD9bfmvEe5mcF62WQlvzFz7O37Q6sO6thStLu8mlj6ZTV3LYp//5vtvz
	wB1lJZbijERDLeai4kQA7uJcmrsCAAA=
X-Original-Sender: mike_spertus@symantec.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of mike_spertus@symantec.com designates 166.98.1.209 as permitted
 sender) smtp.mail=mike_spertus@symantec.com;       dmarc=pass (p=NONE
 dis=NONE) header.from=symantec.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17639
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17639>

--_000_9A3E0561DCF227429F72080EA81ADBC95084454075TUS1XCHEVSPIN_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Comments in Green

From: Arthur O'Dwyer [mailto:arthur.j.odwyer@gmail.com]
Sent: Thursday, April 30, 2015 3:55 PM
To: std-proposals@isocpp.org
Cc: Michael Spertus; arthur.j.odwyer@gmail.com
Subject: Re: Comments on N4470 "Variadic lock_guard"

On Thursday, April 30, 2015 at 6:44:50 AM UTC-7, Michael Spertus wrote:

Thanks for your comments.  Arthur,

1.       Absolutely, the proposal is meant to be deadlock-free, and I just =
embarrassingly put in the wording wrong. Corrected wording will be on the w=
iki. (I realized this right after submitting, but it was too late=E2=80=A6 =
I did give my students an extra credit problem to find the mistake in the p=
aper).
Aha. This definitely removes 70% of my objection to the proposal. :)

 Great. I would object to the proposal without this as well =E2=98=BA

2.       I considered requiring that all the mutex types be the same as you=
 suggest, but some of the most important use cases require different lock t=
ypes (like Howard=E2=80=99s operator=3D example in the paper), and it just =
seems inaccurate to do otherwise.
I wasn't necessarily suggesting that all the Mutexes... should have to be t=
he same; I was just pointing out that in the most common case, where they a=
re the same, it's ugly to force the user to write the same type many times =
in a row.  I deliberately didn't go down the rabbit hole of how to implemen=
t the prettier syntax, because I figured I had a strictly better idea with =
lock_tuple =E2=80=94 but you can certainly use SFINAE to allow lock_guard<M=
>'s constructor to take any number of arguments as long as all of them are =
of type M, or you could have lock_guard do type erasure so that the type in=
side the angle brackets no longer particularly matters... Those both have o=
bvious hurdles (where do you keep the extra arguments? type erasure require=
s heap allocation) but that's the general direction in which the rabbit hol=
e would take us.




3.       If N4471 is adopted, then you don=E2=80=99t need to worry about te=
mplate arguments.
auto guard =3D lock_guard(mtx1, mtx2);
N4471 (type deduction for constructors) is astronomically unlikely to get a=
ccepted IMHO, due to the "Challenges" identified in the proposal and the la=
ck of implementations or proposed wording.
Without N4471, we could propose making lock_guard move-constructible (which=
 I think is fine in practice because a lock_guard is just a bundle of refer=
ences, right?), and then we'd have this syntax:

    auto guard =3D make_lock_guard(mtx1, mtx2);


4.       Even without N4471, since all of the common use cases we could thi=
nk of involve 0, 1, or 2 mutexes (note that 0 locks is useful as well), the=
 notational overhead isn=E2=80=99t excessive.
IMHO the notational overhead for 2 mutexes is excessive =E2=80=94 that's wh=
at I meant by "ugly syntax". But this is a minor point, and could be solved=
 by make_lock_guard above.


I=E2=80=99m not averse to making lock_guard movable.


5.       It seems like unique_lock might also want to work with any number =
of mutexes. In that case, a make_unique_lock(=E2=80=A6) would be another wa=
y to avoid specifying the template arguments. (Since lock_guard is not mova=
ble, you can=E2=80=99t do this with lock_guards).
Your proposal doesn't actually specify a variadic unique_lock, though, does=
 it?  If the concepts are coupled, maybe they should be proposed together.
I didn=E2=80=99t get around to including unique_lock in this proposal, as t=
here are some subtleties, but I may do a proposal later


6.       While I sympathize with your desire to avoid raw locking primitive=
s, I think the use cases in the paper are appropriate and of course, explic=
it locks are common in practices. C++ in general has the philosophy of offe=
ring both low-level primitives and high-level abstractions. In any case, if=
 we choose to provide raw locking primitives, I think the relevant question=
 is whether or not they are better if variadic (also see #8 below).

7.       In particular, I think the built-in deadlock avoidance (Once the w=
ording embarrassment from #1 above is fixed!) will result in more reliable =
programs in practice, if only because many user-defined types follow the ru=
le of three=E2=80=99s imprecation to provide assignment operators.
Can you elaborate on what you mean by "if only because ... assignment opera=
tors"?  I don't see how assignment operators and the Rule of Three are rela=
ted to the lock_guard proposal at all...?
 Here is a typical example from the paper due Howard, which I think occurs =
more often than not when a programmer writes a =E2=80=9Csynchronized class=
=E2=80=9D

class X {
  using Mutex =3D std::shared_timed_mutex;
 using ReadLock =3D std::shared_lock<Mutex>;
  mutable Mutex mut_;
  // more data
public: // ...
 X& operator=3D(const X& x) {
    if (this !=3D&x) {
      ReadLock rl(x.mut_, std::defer_lock);
      std::lock_guard<Mutex, ReadLock> lck(mut_, rl);
      // assign data ...
    }
    return *this;
  }
  // ...
};

8.       I=E2=80=99m having trouble seeing any reason we shouldn=E2=80=99t =
allow lock_guard to be variadic. The proposal is easy to ignore if you don=
=E2=80=99t like it, and IMO doesn=E2=80=99t add conceptual complexity. =E2=
=80=9Cstd::lock_guard can manage a set of locks of diverse types, just like=
 std::lock=E2=80=9D. I=E2=80=99ve never heard any of my students or coworke=
rs say that std::lock is more confusing because it was variadic.
std::lock is confusing because it's underspecified. ;)  This is way off-top=
ic, but I wonder how many people trust std::lock in practice, and how many =
simply roll their own lock-ordering scheme and/or exponential backoff schem=
e and/or whatever other schemes are popular for avoiding deadlock. I don't =
do synchronization stuff myself, but I wonder whether people who do, actual=
ly trust their standard library's std::lock to avoid livelock. And when the=
y move to a different platform, do they see the same performance characteri=
stics?

I think std::lock is a lot better for the vast majority of people than roll=
ing their own, but agree this is off topic, so let=E2=80=99s discuss over b=
eer in Lenexa=E2=80=A6

The value of std::lock_guard is that it's super simple, just like std::mute=
x. If I want a super simple thing, I use lock_guard; if I want a super robu=
st and DWIM thing, I use some higher-level system that supports transaction=
s or whatever, instead of continuing to mess around with raw locks. The que=
stion is whether this proposal is making lock_guard look more like a super =
robust and DWIM thing and attractive to newbies, when in fact it's still ve=
ry dangerous under the hood.

=E2=80=93Arthur

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--_000_9A3E0561DCF227429F72080EA81ADBC95084454075TUS1XCHEVSPIN_
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40"><head><meta http-equiv=3DContent-Type content=
=3D"text/html; charset=3Dutf-8"><meta name=3DGenerator content=3D"Microsoft=
 Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
code
	{mso-style-priority:99;
	font-family:"Courier New";}
span.styled-by-prettify
	{mso-style-name:styled-by-prettify;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:#1F497D;}
..MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3D"#0563C1=
" vlink=3D"#954F72"><div class=3DWordSection1><p class=3DMsoNormal><span st=
yle=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;color:#00B050'>Com=
ments in Green<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'fon=
t-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p>&nbsp;</=
o:p></span></p><p class=3DMsoNormal><b><span style=3D'font-size:11.0pt;font=
-family:"Calibri",sans-serif'>From:</span></b><span style=3D'font-size:11.0=
pt;font-family:"Calibri",sans-serif'> Arthur O'Dwyer [mailto:arthur.j.odwye=
r@gmail.com] <br><b>Sent:</b> Thursday, April 30, 2015 3:55 PM<br><b>To:</b=
> std-proposals@isocpp.org<br><b>Cc:</b> Michael Spertus; arthur.j.odwyer@g=
mail.com<br><b>Subject:</b> Re: Comments on N4470 &quot;Variadic lock_guard=
&quot;<o:p></o:p></span></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div>=
<p class=3DMsoNormal>On Thursday, April 30, 2015 at 6:44:50 AM UTC-7, Micha=
el Spertus wrote:<o:p></o:p></p><blockquote style=3D'border:none;border-lef=
t:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-ri=
ght:0in'><div><p><span style=3D'font-size:11.0pt;font-family:"Calibri",sans=
-serif;color:#1F497D'>Thanks for your comments. &nbsp;Arthur,</span><o:p></=
o:p></p><p><span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif=
;color:#1F497D'>1.</span><span style=3D'font-size:7.0pt;color:#1F497D'>&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=3D'font-size:11.0pt;fon=
t-family:"Calibri",sans-serif;color:#1F497D'>Absolutely, the proposal is me=
ant to be deadlock-free, and I just embarrassingly put in the wording wrong=
.. Corrected wording will be on the wiki. (I realized this right after submi=
tting, but it was too late=E2=80=A6 I did give my students an extra credit =
problem to find the mistake in the paper).</span><o:p></o:p></p></div></blo=
ckquote><div><p class=3DMsoNormal>Aha. This definitely removes 70% of my ob=
jection to the proposal. :)<o:p></o:p></p></div><div><p class=3DMsoNormal><=
o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>&nbsp;<span style=3D'co=
lor:#00B050'>Great. I would object to the proposal without this as well </s=
pan><span style=3D'font-family:Wingdings;color:#00B050'>J</span><span style=
=3D'color:#00B050'><o:p></o:p></span></p></div><blockquote style=3D'border:=
none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:=
4.8pt;margin-right:0in'><div><p><span style=3D'font-size:11.0pt;font-family=
:"Calibri",sans-serif;color:#1F497D'>2.</span><span style=3D'font-size:7.0p=
t;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=3D=
'font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I conside=
red requiring that all the mutex types be the same as you suggest, but some=
 of the most important use cases require different lock types (like Howard=
=E2=80=99s operator=3D example in the paper), and it just seems inaccurate =
to do otherwise.</span><o:p></o:p></p></div></blockquote><div><p class=3DMs=
oNormal>I wasn't necessarily suggesting that all the <span style=3D'font-fa=
mily:"Courier New"'>Mutexes...</span> should <i>have</i> to be the same; I =
was just pointing out that in the most common case, where they <i>are</i> t=
he same, it's ugly to force the user to write the same type many times in a=
 row. &nbsp;I deliberately didn't go down the rabbit hole of how to impleme=
nt the prettier syntax, because I figured I had a strictly better idea with=
 <span style=3D'font-family:"Courier New"'>lock_tuple</span> =E2=80=94 but =
you can certainly use SFINAE to allow <span style=3D'font-family:"Courier N=
ew"'>lock_guard&lt;M&gt;</span>'s constructor to take any number of argumen=
ts as long as all of them are of type <span style=3D'font-family:"Courier N=
ew"'>M</span>, or you could have <span style=3D'font-family:"Courier New"'>=
lock_guard</span> do type erasure so that the type inside the angle bracket=
s no longer particularly matters... Those both have obvious hurdles (where =
do you keep the extra arguments? type erasure requires heap allocation) but=
 that's the general direction in which the rabbit hole would take us.<o:p><=
/o:p></p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p=
 class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>&nb=
sp;<o:p></o:p></p></div><blockquote style=3D'border:none;border-left:solid =
#CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'=
><div><p><span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;c=
olor:#1F497D'>3.</span><span style=3D'font-size:7.0pt;color:#1F497D'>&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=3D'font-size:11.0pt;font-=
family:"Calibri",sans-serif;color:#1F497D'>If N4471 is adopted, then you do=
n=E2=80=99t need to worry about template arguments.<br>auto guard =3D lock_=
guard(mtx1, mtx2);</span><o:p></o:p></p></div></blockquote><div><p class=3D=
MsoNormal>N4471 (type deduction for constructors) is astronomically unlikel=
y to get accepted IMHO, due to the &quot;Challenges&quot; identified in the=
 proposal and the lack of implementations or proposed wording.<o:p></o:p></=
p></div><div><p class=3DMsoNormal>Without N4471, we could propose making <s=
pan style=3D'font-family:"Courier New"'>lock_guard</span> move-constructibl=
e (which <i>I think</i> is fine in practice because a <span style=3D'font-f=
amily:"Courier New"'>lock_guard</span> is just a bundle of references, righ=
t?), and then we'd have this syntax:<o:p></o:p></p></div><div><p class=3DMs=
oNormal><o:p>&nbsp;</o:p></p></div><div style=3D'border:solid #BBBBBB 1.0pt=
;padding:0in 0in 0in 0in;word-wrap: break-word'><div><p class=3DMsoNormal s=
tyle=3D'background:#FAFAFA'><span class=3Dstyled-by-prettify><span style=3D=
'font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp; &nbsp; </sp=
an></span><span class=3Dstyled-by-prettify><span style=3D'font-size:10.0pt;=
font-family:"Courier New";color:#000088'>auto</span></span><span class=3Dst=
yled-by-prettify><span style=3D'font-size:10.0pt;font-family:"Courier New";=
color:black'> guard </span></span><span class=3Dstyled-by-prettify><span st=
yle=3D'font-size:10.0pt;font-family:"Courier New";color:#666600'>=3D</span>=
</span><span class=3Dstyled-by-prettify><span style=3D'font-size:10.0pt;fon=
t-family:"Courier New";color:black'> make_lock_guard</span></span><span cla=
ss=3Dstyled-by-prettify><span style=3D'font-size:10.0pt;font-family:"Courie=
r New";color:#666600'>(</span></span><span class=3Dstyled-by-prettify><span=
 style=3D'font-size:10.0pt;font-family:"Courier New";color:black'>mtx1</spa=
n></span><span class=3Dstyled-by-prettify><span style=3D'font-size:10.0pt;f=
ont-family:"Courier New";color:#666600'>,</span></span><span class=3Dstyled=
-by-prettify><span style=3D'font-size:10.0pt;font-family:"Courier New";colo=
r:black'> mtx2</span></span><span class=3Dstyled-by-prettify><span style=3D=
'font-size:10.0pt;font-family:"Courier New";color:#666600'>);</span></span>=
<span style=3D'font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></spa=
n></p></div></div><div><p class=3DMsoNormal><span style=3D'color:#1F497D'><=
o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span style=3D'color:#00B05=
0'> <o:p></o:p></span></p></div><blockquote style=3D'border:none;border-lef=
t:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-ri=
ght:0in'><div><p><span style=3D'font-size:11.0pt;font-family:"Calibri",sans=
-serif;color:#1F497D'>4.</span><span style=3D'font-size:7.0pt;color:#1F497D=
'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=3D'font-size:11.0=
pt;font-family:"Calibri",sans-serif;color:#1F497D'>Even without N4471, sinc=
e all of the common use cases we could think of involve 0, 1, or 2 mutexes =
(note that 0 locks is useful as well), the notational overhead isn=E2=80=99=
t excessive.</span><o:p></o:p></p></div></blockquote><div><p class=3DMsoNor=
mal>IMHO the notational overhead for 2 mutexes <i>is</i> excessive =E2=80=
=94 that's what I meant by &quot;ugly syntax&quot;. But this is a minor poi=
nt, and could be solved by <span style=3D'font-family:"Courier New"'>make_l=
ock_guard</span> above.<o:p></o:p></p></div><div><p class=3DMsoNormal><span=
 style=3D'color:#00B050'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><=
span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F49=
7D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span style=3D'color:#=
00B050'>I=E2=80=99m not averse to making lock_guard movable.<o:p></o:p></sp=
an></p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><blockquo=
te style=3D'border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in=
 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p><span style=3D'font-size=
:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>5.</span><span styl=
e=3D'font-size:7.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </=
span><span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;color=
:#1F497D'>It seems like unique_lock might also want to work with any number=
 of mutexes. In that case, a make_unique_lock(=E2=80=A6) would be another w=
ay to avoid specifying the template arguments. (Since lock_guard is not mov=
able, you can=E2=80=99t do this with lock_guards).</span><o:p></o:p></p></d=
iv></blockquote><div><p class=3DMsoNormal>Your proposal doesn't actually sp=
ecify a variadic <span style=3D'font-family:"Courier New"'>unique_lock</spa=
n>, though, does it? &nbsp;If the concepts are coupled, maybe they should b=
e proposed together.<o:p></o:p></p></div><div><p class=3DMsoNormal><span st=
yle=3D'color:#00B050'>I didn=E2=80=99t get around to including unique_lock =
in this proposal, as there are some subtleties, but I may do a proposal lat=
er<o:p></o:p></span></p></div><div><p class=3DMsoNormal>&nbsp;<o:p></o:p></=
p></div><blockquote style=3D'border:none;border-left:solid #CCCCCC 1.0pt;pa=
dding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p><span s=
tyle=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>6.=
</span><span style=3D'font-size:7.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; </span><span style=3D'font-size:11.0pt;font-family:"Calibri"=
,sans-serif;color:#1F497D'>While I sympathize with your desire to avoid raw=
 locking primitives, I think the use cases in the paper are appropriate and=
 of course, explicit locks are common in practices. C++ in general has the =
philosophy of offering both low-level primitives and high-level abstraction=
s. In any case, if we choose to provide raw locking primitives, I think the=
 relevant question is whether or not they are better if variadic (also see =
#8 below).</span><o:p></o:p></p><p><span style=3D'font-size:11.0pt;font-fam=
ily:"Calibri",sans-serif;color:#1F497D'>7.</span><span style=3D'font-size:7=
..0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=
=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>In par=
ticular, I think the built-in deadlock avoidance (Once the wording embarras=
sment from #1 above is fixed!) will result in more reliable programs in pra=
ctice, if only because many user-defined types follow the rule of three=E2=
=80=99s imprecation to provide assignment operators.</span><o:p></o:p></p><=
/div></blockquote><div><p class=3DMsoNormal>Can you elaborate on what you m=
ean by &quot;if only because ... assignment operators&quot;? &nbsp;I don't =
see how assignment operators and the Rule of Three are related to the lock_=
guard proposal at all...?<o:p></o:p></p></div><div><p class=3DMsoNormal>&nb=
sp;<span style=3D'color:#00B050'>Here is a typical example from the paper d=
ue Howard, which I think occurs more often than not when a programmer write=
s a =E2=80=9Csynchronized class=E2=80=9D<o:p></o:p></span></p><p class=3DMs=
oNormal><span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;co=
lor:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span style=
=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>class X { <o:=
p></o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:11.0pt;fon=
t-family:"Courier New";color:#00B050'>=C2=A0=C2=A0using Mutex =3D std::shar=
ed_timed_mutex;<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'fo=
nt-size:11.0pt;font-family:"Courier New";color:#00B050'> =C2=A0using ReadLo=
ck =3D std::shared_lock&lt;Mutex&gt;;<o:p></o:p></span></p><p class=3DMsoNo=
rmal><span style=3D'font-size:11.0pt;font-family:"Courier New";color:#00B05=
0'>=C2=A0 mutable Mutex mut_; <o:p></o:p></span></p><p class=3DMsoNormal><s=
pan style=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>=C2=
=A0=C2=A0// more data<o:p></o:p></span></p><p class=3DMsoNormal><span style=
=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>public: // ..=
..<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:11.0pt=
;font-family:"Courier New";color:#00B050'> =C2=A0X&amp; operator=3D(const X=
&amp; x) {<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'font-si=
ze:11.0pt;font-family:"Courier New";color:#00B050'>=C2=A0=C2=A0 =C2=A0if (t=
his !=3D&amp;x) {<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'=
font-size:11.0pt;font-family:"Courier New";color:#00B050'>=C2=A0=C2=A0=C2=
=A0=C2=A0 =C2=A0ReadLock rl(x.mut_, std::defer_lock);<o:p></o:p></span></p>=
<p class=3DMsoNormal><span style=3D'font-size:11.0pt;font-family:"Courier N=
ew";color:#00B050'>=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0std::lock_guard&lt;Mutex,=
 ReadLock&gt; lck(mut_, rl);<o:p></o:p></span></p><p class=3DMsoNormal><spa=
n style=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>=C2=A0=
=C2=A0=C2=A0=C2=A0 =C2=A0// assign data ...<o:p></o:p></span></p><p class=
=3DMsoNormal><span style=3D'font-size:11.0pt;font-family:"Courier New";colo=
r:#00B050'>=C2=A0=C2=A0=C2=A0 }<o:p></o:p></span></p><p class=3DMsoNormal><=
span style=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>=C2=
=A0 =C2=A0=C2=A0return *this; <o:p></o:p></span></p><p class=3DMsoNormal><s=
pan style=3D'font-size:11.0pt;font-family:"Courier New";color:#00B050'>=C2=
=A0=C2=A0} <o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'font-s=
ize:11.0pt;font-family:"Courier New";color:#00B050'>=C2=A0=C2=A0// ... <o:p=
></o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:11.0pt;font=
-family:"Courier New";color:#00B050'>};<o:p></o:p></span></p></div><blockqu=
ote style=3D'border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0i=
n 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p><span style=3D'font-siz=
e:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>8.</span><span sty=
le=3D'font-size:7.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <=
/span><span style=3D'font-size:11.0pt;font-family:"Calibri",sans-serif;colo=
r:#1F497D'>I=E2=80=99m having trouble seeing any reason we shouldn=E2=80=99=
t allow lock_guard to be variadic. The proposal is easy to ignore if you do=
n=E2=80=99t like it, and IMO doesn=E2=80=99t add conceptual complexity. =E2=
=80=9Cstd::lock_guard can manage a set of locks of diverse types, just like=
 std::lock=E2=80=9D. I=E2=80=99ve never heard any of my students or coworke=
rs say that std::lock is more confusing because it was variadic.</span><o:p=
></o:p></p></div></blockquote><div><p class=3DMsoNormal><span style=3D'font=
-family:"Courier New"'>std::lock</span> is confusing because it's underspec=
ified. ;) &nbsp;This is way off-topic, but I wonder how many people trust <=
span style=3D'font-family:"Courier New"'>std::lock</span> in practice, and =
how many simply roll their own lock-ordering scheme and/or exponential back=
off scheme and/or whatever other schemes are popular for avoiding deadlock.=
 I don't do synchronization stuff myself, but I wonder whether people who d=
o, actually trust their standard library's <span style=3D'font-family:"Cour=
ier New"'>std::lock</span> to avoid livelock. And when they move to a diffe=
rent platform, do they see the same performance characteristics?<o:p></o:p>=
</p></div><div><p class=3DMsoNormal><span style=3D'color:#1F497D'><o:p>&nbs=
p;</o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:11.0pt;fon=
t-family:"Calibri",sans-serif;color:#00B050'>I think std::lock is a lot bet=
ter for the vast majority of people than rolling their own, but agree this =
is off topic, so let=E2=80=99s discuss over beer in Lenexa=E2=80=A6<o:p></o=
:p></span></p><p class=3DMsoNormal><span style=3D'font-size:11.0pt;font-fam=
ily:"Calibri",sans-serif;color:#00B050'><o:p>&nbsp;</o:p></span></p></div><=
div><p class=3DMsoNormal>The value of <span style=3D'font-family:"Courier N=
ew"'>std::lock_guard</span> is that it's super simple, just like <span styl=
e=3D'font-family:"Courier New"'>std::mutex</span>. If I want a super simple=
 thing, I use <span style=3D'font-family:"Courier New"'>lock_guard</span>; =
if I want a super robust and DWIM thing, I use some higher-level system tha=
t supports transactions or whatever, instead of continuing to mess around w=
ith raw locks. The question is whether this proposal is making <span style=
=3D'font-family:"Courier New"'>lock_guard</span> <i>look more like</i> a su=
per robust and DWIM thing and attractive to newbies, when <i>in fact</i> it=
's still very dangerous under the hood.<o:p></o:p></p></div><div><p class=
=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>=E2=80=93=
Arthur<o:p></o:p></p></div></div></div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--_000_9A3E0561DCF227429F72080EA81ADBC95084454075TUS1XCHEVSPIN_--

.
