MESSAGE
DATE | 2016-12-21 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] (fwd) Re: Threads and Object Methods
|
From learn-bounces-at-nylxs.com Wed Dec 21 17:21:37 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 316E7161316; Wed, 21 Dec 2016 17:21:37 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id CF979161317 for ; Wed, 21 Dec 2016 17:20:24 -0500 (EST) Received: from panix3.panix.com (panix3.panix.com [166.84.1.3]) by mailbackend.panix.com (Postfix) with ESMTP id C41AC13F44 for ; Wed, 21 Dec 2016 17:20:23 -0500 (EST) Received: by panix3.panix.com (Postfix, from userid 20529) id 830392EB55; Wed, 21 Dec 2016 17:20:23 -0500 (EST) From: Ruben Safir To: learn-at-nylxs.com User-Agent: tin/2.2.1-20140504 ("Tober an Righ") (UNIX) (NetBSD/6.1.5 (i386)) Message-Id: <20161221222023.830392EB55-at-panix3.panix.com> Date: Wed, 21 Dec 2016 17:20:23 -0500 (EST) Subject: [Learn] (fwd) Re: Threads and Object Methods 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: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
-- forwarded message -- Path: reader1.panix.com!panix!goblin2!goblin.stu.neva.ru!ecngs!feeder2.ecngs.de!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Sun, 18 Dec 2016 15:40:30 -0600 Subject: Re: Threads and Object Methods Newsgroups: comp.lang.c++ References: <6d72eead-14c9-4db9-a9c6-f68c2b27f1a4-at-googlegroups.com> From: Vir Campestris Date: Sun, 18 Dec 2016 21:40:31 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <7pSdnevF5InTn8rFnZ2dnUU78W3NnZ2d-at-brightview.co.uk> Lines: 55 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-VtkexjPPnbI7EqckZJ5dejFTMXN6gFDivz19C09Rn1QWbViai7EU+dLgOpn+G5JW71q2k0fQtPCTh+G!6RNG8aqxqiLmugP5Kr4BHexxK1u+Dj+JtvsCg4V37px1LskrQI1IT5wxLokd0/aYaA2v4dVB0wtA!a7fYpZ5jsPhIZyRI9ZBsKSuXQ2o= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2845 Xref: panix comp.lang.c++:1126120
On 18/12/2016 14:36, ruben safir wrote: > On 12/18/2016 06:09 AM, ?? Tiib wrote: >> On Sunday, 18 December 2016 11:49:07 UTC+2, ruben safir wrote: >>> Why can't the threads library handle object methods that are not static >>> to the class >>> >>> >>> such as std::thread paint(read_chunk); >>> paint.detach(); >>> >>> >>> where read_chunk is an method of an object of class Images. >> >> Again some voodoo trying-out nonsense that we can't even >> copy-paste and run? :-/ The 'std::thread' *can* use non-static >> methods. However the caller has to supply arguments (starting >> from 'this') to it. >> >> #include >> #include >> >> struct Reader >> { >> void read_chunk() >> { >> std::cout << "quod erat demonstrandum" << std::endl; >> } >> }; >> >> int main() >> { >> std::thread paint(&Reader::read_chunk, Reader()); >> paint.join(); >> } >> >> See? It is easy peasy. >> > > if you call it like that it loses its context of the object that > instantated it which, especially in this case, it needs in order to do > its job. > You're missing the second parameter to the function. Perhaps if he'd written
Reader foo; std::thread paint(&reader::read_chunk, &foo);
it would have made more sense to you. You can pass args to the function, which may include a pointer to an object of the type. I prefer to pass a pointer to a static member function for the first parameter which takes a pointer to an object of the class and invokes a corresponding non-static member.
Andy
-- end of forwarded message -- _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|