Original Post
ok i've been redesigning my app from the ground using memory leak detection, exceptions, and threads.
Everything works properly except threads.
I've been testing the threads. I've got a thread class that begins() and ends() threads. i've tested it by making 3 threads
and having it print to a file the mem address (to see which thread is printing what) and a static count variable that's in the function. Like so:
the text file shows that the 3 threads are being called almost at the same time, but I notice it misprints the count number or the memory address in correctly. By that it looks like it was in the middle of executing my file << statement and it switched threads. Well I decide to add mutexs (then I also tried criticalsections) so my thread class is derived from mutex (hence the "this->Lock/Unlock()" calls) And this doesn't seem to fix it either.
I'd really like it to execute one pass through the while loop completely without messing up. Anybody have thoughts or suggestions?
-Pac
[edited by - Pactuul on June 15, 2002 1:23:15 AM]
DWORD Thread::ThreadProc()
{
static fstream file;
static count = 0;
count++;
if (count == 1)
file.open("test.txt",ios::out);
while (d_bIsRunning)
{
this->Lock();
count++;
file << &(*this) << " " << count << endl;
this->Unlock();
}
return 0;
}