Search code examples
windowsmultithreadingvisual-c++visual-studio-2008beginthreadex

unhandled read exception in thread after passing class into thread


http://pastebin.com/QPab6nkp is all my code, pretty messy and unfinished.

I found where is an error - i think im passing philosophist exemplar into thread incorectly, because into the thread, philosophist *ph = static_cast<philosophist*>(params); - that ph variable contains some garbage numbers insead of what i've passed (591519915,-519258915 and so on). Of course when i try to getID of philosophist, there is no such id in array of semaphors, gSems. How to pass that class into thread correctly?


Solution

  • _beginthreadex(NULL, 0, &philosophistFunction, ph1, 0, 0);
    there is no need for & before ph1