220 15346 <A791A4F3-FA95-4932-9DE9-A112363BE5B6@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: get count of std::weak_ptr objects tracking a
 shared resource
Date: Sun, 28 Dec 2014 14:29:48 +0800
Lines: 43
Approved: news@gmane.org
Message-ID: <A791A4F3-FA95-4932-9DE9-A112363BE5B6@gmail.com>
References: <a9c1d3d5-761d-44df-b722-ae649440ea77@isocpp.org> <4797942.dAdOve4yz0@tjmaciei-mobl4> <CAFk2RUYxhUoBHap95bQVwZbFrjJq6i37FAEec2LG6gYguenJkQ@mail.gmail.com> <549C50C1.8060008@gmail.com> <71d4ea44-aec9-4bfa-a1a8-ba81ca745b84@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\))
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1419748210 23422 80.91.229.3 (28 Dec 2014 06:30:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 28 Dec 2014 06:30:10 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRB2OG72SAKGQE7Y5K2KY@isocpp.org Sun Dec 28 07:30:03 2014
Return-path: <std-proposals+bncBCW25A7E3QCRB2OG72SAKGQE7Y5K2KY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f199.google.com ([209.85.223.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRB2OG72SAKGQE7Y5K2KY@isocpp.org>)
	id 1Y57MY-0004ad-St
	for gclcip-std-proposals@m.gmane.org; Sun, 28 Dec 2014 07:30:03 +0100
Original-Received: by mail-ie0-f199.google.com with SMTP id rp18sf70867509iec.10
        for <gclcip-std-proposals@m.gmane.org>; Sat, 27 Dec 2014 22:30:01 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:content-type:mime-version:subject:from
         :in-reply-to:date:content-transfer-encoding:message-id:references:to
         :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=WBo1PBC2ouqKjzM24TIHDeB32LYtQ8TPF8vCVMLriz0=;
        b=N+2nRm8owHfYd1E+4I3knsluVRy7XYmhc5LxFfwmMFJWFM41rU7nKCnTq2qjdqCCS0
         tl4a7uBb7RLWG7+sKGByx22NlsriZ47ukXm4eu9QXEJApu5DShkm26r95tbkgs2PL9yu
         OnXzFsBIDK+X5JIodNN8amXd2SbWr5ZbbbQeBNB1WfGfIb51haqGjOpKGDTvB7NLLYmK
         d5WnZkDyCr1398J2RkkJffFxR1H283yAamG4RUd0mgpRoiBEeSOcaGEY8B4NSWeXuoQq
         qtOinxByJx5+JjditLJAg81CryrARxndPMHtF5jaAgISopEeVRuX/A35U/aMew9HRvUd
         ynEg==
X-Gm-Message-State: ALoCoQmDO2dbCgczUxEIO4drG0uqZ2lDxEfWxMoCgsy6JKyFz2XpfGhwAxFmAHh9eNoAc5nzSuFl
X-Received: by 10.182.252.164 with SMTP id zt4mr38205010obc.1.1419748201862;
        Sat, 27 Dec 2014 22:30:01 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.157.194 with SMTP id g185ls4139580ioe.25.gmail; Sat, 27
 Dec 2014 22:30:01 -0800 (PST)
X-Received: by 10.66.171.206 with SMTP id aw14mr79945502pac.40.1419748201007;
        Sat, 27 Dec 2014 22:30:01 -0800 (PST)
Original-Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com. [2607:f8b0:400e:c03::22d])
        by mx.google.com with ESMTPS id ns5si10018562pbc.178.2014.12.27.22.30.00
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 27 Dec 2014 22:30:01 -0800 (PST)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22d as permitted sender) client-ip=2607:f8b0:400e:c03::22d;
Original-Received: by mail-pa0-f45.google.com with SMTP id lf10so15502765pab.32
        for <std-proposals@isocpp.org>; Sat, 27 Dec 2014 22:30:00 -0800 (PST)
X-Received: by 10.70.56.37 with SMTP id x5mr47772357pdp.86.1419748200800;
        Sat, 27 Dec 2014 22:30:00 -0800 (PST)
Original-Received: from [172.20.10.2] ([121.54.44.91])
        by mx.google.com with ESMTPSA id qq6sm32259251pbb.20.2014.12.27.22.29.57
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 27 Dec 2014 22:30:00 -0800 (PST)
In-Reply-To: <71d4ea44-aec9-4bfa-a1a8-ba81ca745b84@isocpp.org>
X-Mailer: Apple Mail (2.1993)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22d as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.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:15346
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/15346>


> On 2014=E2=80=9312=E2=80=9328, at 1:07 PM, Ramkumar Revanur <write2ramkum=
ar@gmail.com> wrote:
>=20
> Just as new shared_ptr can be created to the same resource from existing =
shared_ptr. The reliability of the "weak_count" is same as the reliability =
of use_count on a shared_ptr.

A combination of use_count and weak_count is safer, though, because a poten=
tially-last owner can check that there are no other potential owners on oth=
er threads. The weak count would need to be checked (evaluated) first thoug=
h, which is a bit tricky with unordered expression evaluation semantics.

For that matter, a total reference_count which is the sum of strong and wea=
k references would accomplish this more elegantly. It would be a drop-in re=
placement for use_count.

Applications that want to safely invalidate unsynchronized weak references =
need another new primitive, perhaps call it expire(), which atomically rese=
ts if unique. Then the caller can check whether the reset actually occurred=
.. This is needed to make the design in the OP safe against a race between a=
 cache eviction (or clearing) and a cache access.

Whether cache control is a valid use-case of weak_ptr, I=E2=80=99m not real=
ly sure. Why not? It=E2=80=99s unusual but clever. Control blocks introduce=
 some inefficiency, but it sounds like a big shortcut and efficiency gain v=
s. shared_ptr alone.

Anyway, the proposed extensions won=E2=80=99t add any overhead, and there a=
re surely other multithreaded applications out there with unsafe weak refer=
ences.

--=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/.

.
