Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #47488

thread concurancy

From Popping mad <rainbow@colition.gov>
Newsgroups comp.lang.c++
Subject thread concurancy
Date 2016-12-21 20:48 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <o3eprl$1pf$2@reader1.panix.com> (permalink)

Show all headers | View raw


:(

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 <iostream>
#include <thread>
#include <mutex>
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<std::mutex> 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<char>(*loc_canvas_index) << std::endl;
				loc_canvas_index++;
			}

Back to comp.lang.c++ | Previous | NextNext in thread | Find similar | Unroll thread


Thread

thread concurancy Popping mad <rainbow@colition.gov> - 2016-12-21 20:48 +0000
  Re: thread concurancy Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-21 23:39 +0200
    Re: thread concurancy ruben safir <ruben@mrbrklyn.com> - 2016-12-21 23:48 -0500
      Re: thread concurancy Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-22 12:32 +0200
        Re: thread concurancy ruben safir <ruben@mrbrklyn.com> - 2016-12-22 12:13 -0500
          Re: thread concurancy Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-22 20:29 +0200
        Re: thread concurancy scott@slp53.sl.home (Scott Lurndal) - 2016-12-23 14:31 +0000
          Re: thread concurancy Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-23 20:19 +0200
            Re: thread concurancy scott@slp53.sl.home (Scott Lurndal) - 2016-12-23 22:39 +0000
              Re: thread concurancy Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-24 01:31 +0200
    Re: thread concurancy ruben safir <ruben@mrbrklyn.com> - 2016-12-21 23:49 -0500
      Re: thread concurancy "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-12-23 15:19 -0800
  Re: thread concurancy Sal LO <gegefffffff@gmail.com> - 2016-12-22 07:04 -0800
    Re: thread concurancy ruben safir <ruben@mrbrklyn.com> - 2016-12-22 11:00 -0500

csiph-web