#include "pch.h"
#undef UNICODE
#include <windows.h>
#include <iostream>
using namespace std;
 
class Thread
{
public:
	HANDLE handle;
	virtual void run () { }
	void start();
};
 
class MyThread : public Thread
{
public:
	void run() 
	{ 
		while (true)
			cout << "Hello from thread" << endl;
	}
};
 
DWORD WINAPI f (void * p)
{
	Thread * t = (Thread *) p;
	t->run ();
	return 0;
}
 
void Thread::start()
{
	HANDLE handle =
		CreateThread
		   (NULL, // lpThreadAttributes,
			0, // dwStackSize,
			f, // lpStartAddress,
			(void *) this, // lpParameter,
			0, //  dwCreationFlags,
			NULL // lpThreadId
		    );
 
}
 
int main()
{
	MyThread t;
	t.start ();
	WaitForSingleObject (t.handle, 1000);
    cout << "Konec" << endl; 
}
#include "pch.h"
#undef UNICODE
#include <windows.h>
#include <iostream>
using namespace std;
 
DWORD WINAPI f (void * p)
{
	while (true)
		cout << "Hello from thread" << endl;
	return 0;
}
 
int main()
{
	DWORD threadid;
 
	HANDLE h = 
	   CreateThread 
	   (NULL, // lpThreadAttributes,
		0, // dwStackSize,
		f, // lpStartAddress,
		(void *) 0, // lpParameter,
		0, //  dwCreationFlags,
		NULL // lpThreadId
		);
 
	if (h != NULL)
	{
		cout << "Vlakno vyvoreno" << endl;
		WaitForSingleObject (h, 1000);
		CloseHandle(h);
	}
 
    cout << "Konec" << endl; 
}
 
thread_2019.txt · Last modified: 2019/04/04 16:08 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki