Hi Guys,
i wrote a program that starts another thread. In one case i thought that i have introduced a memory leak and i should get a segmentation fault but i didn't !! That's kind of puzzled me so i decided to post it here.
#include <iostream>
#include <windows.h>
#include <process.h>
using namespace std;
void silly( void * );
int main()
{
cout << "Now in the main() function.\n" << endl;
int *i = new int(10);
_beginthread( silly, 0, i );
delete i;
cout << "deleted" << endl;
Sleep( 1000 );
cout << "didn't crash?" << endl;
}
void silly( void *arg )
{
Sleep(100);
cout << "The silly() function was passed %d\n" << (int*)arg << endl;
}
Output:
Now in the main() function.
deleted
The silly() function was passed %d
00316990
didn't crash?
as you guys can see the silly function is being pointer to a dynamically allocated int and i delete that memory before the silly function prints it. But it still doesn't crash? I was expecting it to give me a dump.