/*
 * http://charette.no-ip.com:81/programming/2011-06-27_StdThread/
 * $Id: 2011-07-16_leak.cpp 271 2011-07-17 04:57:47Z stephane $
 *
 * Example code with a memory leak when using std::thread in C++0x.
 *
 * Compiled with the following:
 *
 *		g++ -std=c++0x -pthread 2011-07-16_leak.cpp
 */


#include <thread>
#include <iostream>


void workerThread( void )
{
	std::cout << "Mr. Thread runs here" << std::endl;

	// worker thread exits once we hit this next line
	return;
}


int main( int argc, char *argv[] )
{
	std::cout << "This is the main thread.  Now we create a new thread." << std::endl;
	std::thread t = workerThread;

	// failure to join() or detach() the thread will cause a resource leak,
	// and in this simple example will also result in random output as the
	// thread may or may not have completed by the time the main thread exits
//	t.join();

	std::cout << "Main thread is exiting.  Worker thread will be killed if it hasn't exited." << std::endl;

	// application (including threads) ends automatically once the main thread returns
	return 0;
}

