MESSAGE
DATE | 2016-12-21 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] thread concurancy
|
From learn-bounces-at-nylxs.com Wed Dec 21 15:49:20 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 81D82161312; Wed, 21 Dec 2016 15:49:20 -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 5CD40160E77; Wed, 21 Dec 2016 15:49:18 -0500 (EST) To: learn-at-nylxs.com From: Ruben Safir Message-ID: <2a2adad8-9115-46f3-f74f-82ea0d132614-at-mrbrklyn.com> Date: Wed, 21 Dec 2016 15:49:18 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Subject: [Learn] 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: , 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 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++; }
-- 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
|
|