MESSAGE
DATE | 2016-12-21 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] (fwd) thread concurancy
|
From learn-bounces-at-nylxs.com Wed Dec 21 17:19:42 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 1CD85161312; Wed, 21 Dec 2016 17:19:42 -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 D4780160E77 for ; Wed, 21 Dec 2016 17:19:39 -0500 (EST) Received: from panix3.panix.com (panix3.panix.com [166.84.1.3]) by mailbackend.panix.com (Postfix) with ESMTP id BD93213EAC for ; Wed, 21 Dec 2016 17:19:39 -0500 (EST) Received: by panix3.panix.com (Postfix, from userid 20529) id A0F5A2EB50; Wed, 21 Dec 2016 17:19:39 -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: <20161221221939.A0F5A2EB50-at-panix3.panix.com> Date: Wed, 21 Dec 2016 17:19:39 -0500 (EST) Subject: [Learn] (fwd) thread concurancy 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!not-for-mail From: Popping mad Newsgroups: comp.lang.c++ Subject: thread concurancy Date: Wed, 21 Dec 2016 20:48:53 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 68 Message-ID: NNTP-Posting-Host: www.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1482353333 1839 96.57.23.82 (21 Dec 2016 20:48:53 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Wed, 21 Dec 2016 20:48:53 +0000 (UTC) To: learn-at-nylxs.com User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e git.gnome.org/git/pan2) Xref: panix comp.lang.c++:1126196
:(
I don't know. I'm very confused about the behavior of this test program I've been right. I'm trying to move date by worker threads from one blob of memory to another and the debugger is saying that the pointers beg and canvas_index is jumping 10 bytes between this two lines
for(int i = 0; i < 10;i++) { t[i] = std::thread([this]{ readin(beg, canvas_index); });
and I'm not sure why. I lost the concurrency somewhere, but can't seem to figure out what I did wrong
#include #include #include std::mutex medco; std::mutex master;
namespace testing{ std::thread t[10]; class PIC { public: PIC():beg{&source[0]} { canvas_index = canvas; std::cout << "Testing Source" << std::endl; for(int i = 0; i<100; i++) { std::cout << i << " " << source[i] << std::endl ; } for(int i = 0; i < 10;i++) { t[i] = std::thread([this]{ readin(beg, canvas_index); }); std::cerr << i << ": Making a thread" << std::endl; sync_canvas_and_input(); } };
void sync_canvas_and_input() { std::cout << "**LOCKING**" << std::endl; std::lock_guard turn(medco); beg += 10; canvas_index += 10; } ~PIC() { std::cerr << "In the destructor" << std::endl; for(int i=0; i<10; i++) { t[i].join(); std::cerr << i << ": Joining a thread" << std::endl; }
}; void readin(char * start, char * loc_canvas_index) { for( int i = 9; i>=0; i-- ) { *loc_canvas_index = start[i]; std::cerr << i << ": Copy " << start[i] << std::endl; std::cerr << i << ": Copied to loc_canvas_index " << reinterpret_cast(*loc_canvas_index) << std::endl; loc_canvas_index++; }
-- end of forwarded message -- _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|