MESSAGE
DATE | 2016-11-16 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] ref use
|
From learn-bounces-at-nylxs.com Wed Nov 16 05:38:21 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id B17D8161312; Wed, 16 Nov 2016 05:38:21 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id C3933160E77 for ; Wed, 16 Nov 2016 05:38:18 -0500 (EST) To: learn-at-nylxs.com From: Ruben Safir Message-ID: <97df36f9-769a-a643-f772-252c082c2618-at-mrbrklyn.com> Date: Wed, 16 Nov 2016 05:38:18 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 Subject: [Learn] ref use X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
[This mail was also posted to comp.lang.c++.]
I'm reading up on concurrency with the thread libraryis C++ Concurrency in action by Anthony Williams and I'm puzzled by one example having to do with sending references of objects through the threads. If you own the text, it is one page 24 where he is callable functions is void update_data_for_widget(widget_id w, widget_data& data);
the call for the thread is std::thread t (update_data_for_widget, w, data); where data is an object, of data I suppose ;)
to do this correctly he says we need to use ref and a reference wrapper
std::thread t(update_data_for_widget, w, std::ref(data) );
Why can't you just send a reference?
std::thread t(update_data_for_widget, w, &data );
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|