Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Vectors / Classes /Threading
    text
    copied!<p>I'm Using Win7 / VS2008 (9) SDK 6/7.1</p> <p>i faced a problem in a code that i'm using<br> the mini version of the code as follows </p> <pre><code>class CONNECTION { int/std::string/bool vars; // just to make it simple CONNECTION ( int defaultvar ); CONNECTION ( const CONNECTION&amp; copycon ) ~CONNECTION ( ); DWORD static WINAPI staticstart( void *param ) //HACK to use createthread on classes { return ((CONNECTION *)param)-&gt;main); } // yea it works fine DWORD main(); }; </code></pre> <p>this class has no default constructor with a copy and a destructor all vars are copied fine and destructor leaves no memleaks, constructor is simple as assigning the paramters to a var .. all vars and code are omitted to make it simple and because they aren't the prob. </p> <pre><code>class main { std::vector&lt;CONNECTION&gt; con; int addcon( int defaultvarofcon ) { CONNECTION temp( defaultvar ); con.push_back( temp ); return con.size() - 1; } } </code></pre> <p>so far so good when i run a console test program that only have an include and this code</p> <pre><code>main mymainclass; mymainclass.addcon( 0 ); </code></pre> <p>program runs fine closes without errors<br> but when i add extra code like </p> <pre><code>main mymainclass; mymainclass.addcon( 0 ); mymainclass.addcon( 1 ); mymainclass.addcon( 2 ); </code></pre> <p>program crashes with access violation after checking my code twice i debugged it step by step on all threads i found out the main thread can read correct values of all vector class/elements in both main thread and worker thread ONLY if i'm using one element at the vector </p> <p>however if i'm using more than one like the second code all data on all elements on their own threads are inaccessible ( bad pointers ) . but on main thread they still correct and showing right values </p> <p>can any one please help me figure out what's wrong with this code ? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload