MESSAGE
DATE | 2016-12-21 |
FROM | Ruben Safir
|
SUBJECT | Re: [Learn] thread concurancy
|
From learn-bounces-at-nylxs.com Wed Dec 21 23:37:35 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 1D32B161312; Wed, 21 Dec 2016 23:37:35 -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 DEED1160E77 for ; Wed, 21 Dec 2016 23:37:31 -0500 (EST) Received: from [10.0.0.62] (www.mrbrklyn.com [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 3BFF31336F for ; Wed, 21 Dec 2016 23:37:31 -0500 (EST) To: learn-at-nylxs.com References: <2a2adad8-9115-46f3-f74f-82ea0d132614-at-mrbrklyn.com> <1482374939422.53063-at-liu.edu> From: Ruben Safir Message-ID: <5d40f92d-f67f-4723-3fbc-d715f3786a2f-at-panix.com> Date: Wed, 21 Dec 2016 23:37:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1482374939422.53063-at-liu.edu> Content-Type: multipart/mixed; boundary="------------F9AE8DB7B02EBA172C533C7F" Subject: Re: [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: , Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
This is a multi-part message in MIME format. --------------F9AE8DB7B02EBA172C533C7F Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit
Blackboard is crap
On 12/21/2016 09:49 PM, Samir Iabbassen wrote: > Hi Ruben, > > if you didn't send the project report, please send it to me along with whatever source code you have so far. the semester is at its end and I need to finalize grading. I know you have spent a lots of time on the project and I will be based on it for your total grading. > Send me your resume and I will forward it to the my friend for the dba position, meanwhile follow the instructions for formal application. > I also got following this morning from another friend if you are interested. > >>Hi guys > > >>Do you know any jr. App Dev looking for a gig in city? > > >>There is job at DOT although not in IT dept. Computer Associate 2 > > >>Let me know. I will send job link when active. > > >>Regards, > > Happy Holidays and see you in spring... > ________________________________________ > From: Ruben Safir > Sent: Wednesday, December 21, 2016 3:49 PM > To: learn-at-nylxs.com > Subject: thread concurancy > > [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 >
-- 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
--------------F9AE8DB7B02EBA172C533C7F Content-Type: text/plain; charset=UTF-8; name="makefile" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="makefile"
tesitng : g++ -Wall -pthread -ggdb ./test.cpp
--------------F9AE8DB7B02EBA172C533C7F Content-Type: text/x-c++src; name="test.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test.cpp"
/* * ===================================================================================== * * Filename: test.cpp * * Description: Threading Experiment * * Version: 1.0 * Created: 12/18/2016 12:46:51 PM * Revision: none * Compiler: gcc * * Author: Ruben Safir (mn), ruben-at-mrbrklyn.com * Company: NYLXS Inc * * ===================================================================================== */
#include #include #include std::mutex medco; std::mutex master;
namespace testing{ std::thread t[10]; class PIC { public: PIC():source_index{&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(); }); std::cerr << i << ": Making a thread" << std::endl; } };
~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 * loc_canvas_index; char * loc_source_index; sync_canvas_and_input(loc_canvas_index, loc_source_index); for( int i = 9; i>=0; i-- ) { *loc_canvas_index = loc_source_index[i]; std::cerr << i << ": Copy " << loc_source_index[i] << std::endl; std::cerr << i << ": Copied to loc_canvas_index " << reinterpret_cast(*loc_canvas_index) << std::endl; loc_canvas_index++; }
}; void sync_canvas_and_input(char * &loc_canvas_index, char * &loc_source_index ) { std::cout << "**LOCKING**" << std::endl; std::lock_guard turn(medco); loc_canvas_index = canvas_index; loc_source_index = source_index; source_index += 10; canvas_index += 10; };
char * get_canvas() { return canvas; } char * get_canvas_index() { return canvas_index; } char * get_source_index() { return source_index; }
private: char * canvas = new char[100]{ 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z', 'z', 'z','z','z','z','z','z','z','z','z' }; char * canvas_index; char source[100] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; char * source_index; }; }//end namespace
int main(int argc, char** argv) { testing::PIC fido; for(int i = 0; i<100;i++) { std::cout << i << " Canvas Position " << fido.get_canvas()[i] << std::endl; }
return 0; }
--------------F9AE8DB7B02EBA172C533C7F Content-Type: text/x-c++src; name="main_png.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="main_png.cpp"
/* * ===================================================================================== * * Filename: main_png.cpp * * Description: PNG Project - main * * Version: 1.0 * Created: 11/30/2016 02:57:46 PM * Revision: 1.0 * Compiler: gcc * * Author: Ruben Safir (mn), ruben-at-mrbrklyn.com * Company: NYLXS Inc * * ===================================================================================== */ #include #include "png_proj.h"
int main(int argc, char **argv) { // const char * image_file_path = nullptr; const char * image_file_path = "/home/ruben/images/tzfat/tzfat_dawn_blended_fused.png"; //const char * image_file_path = "/home/ruben/photo_album/images/135-red_sea_1.png"; png_proj::Image pngtestfile{image_file_path}; // pngtestfile.read_png(); std::cout << "MAIN: line:" << __LINE__ << " char * image size==>" << sizeof(image_file_path) << std::endl; pngtestfile.read_signature(); pngtestfile.read_chunk(); // while(pngtestfile.getNext() < pngtestfile.get_end() ){ // std::cout << "Hey I am not Kosher Bird, yoy can't eat me!!" << std::endl; // }
return EXIT_SUCCESS; }
--------------F9AE8DB7B02EBA172C533C7F Content-Type: text/plain; charset=UTF-8; name="makefile" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="makefile"
CXX:=g++ CXXFLAGS:=-Wall -ggdb -pg -pthread
LDFLAGS:=-L/usr/local/lib/mysql -lmysqlpp -lmysqlclient -lz
mypng : png_proj.o main.o ${CXX} ${CXXFLAGS} -o mypng png_proj.o main.o
main.o : main_png.cpp ${CXX} ${CXXFLAGS} -o main.o -c main_png.cpp
png_proj.o : png_proj.cpp ${CXX} ${CXXFLAGS} -o png_proj.o -c png_proj.cpp
clean : rm png_proj *.o make.deps touch *.cpp *.h
include make.deps make.deps: *.cpp ; gcc -M *.cpp >$-at-
--------------F9AE8DB7B02EBA172C533C7F Content-Type: text/x-c++src; name="png_proj.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="png_proj.cpp"
/* * ===================================================================================== * * Filename: png_proj.cpp * * Description: PNG Project * * Version: 1.0 * Created: 11/15/2016 12:08:44 PM * Revision: none * Compiler: gcc * * Author: Ruben Safir (mn), ruben-at-mrbrklyn.com * Company: NYLXS Inc * * ===================================================================================== */ #include #include #include #include #include |
|