function CreateThread (
Lpthreadattributes:pointer; {Security Settings}
Dwstacksize:dword; {Stack size}
Lpstartaddress:tfnthreadstartroutine; {Entry Function}
Lpparameter:pointer; {function Argument}
Dwcreationflags:dword; {Startup options}
var lpthreadid:dword {output Thread ID}
): Thandle; stdcall; {return thread handle}
1. Return value: Returns the thread handle
A handle is like a pointer, but a pointer can read or write an object, and a handle simply uses the object;
Objects with handles are generally system-level objects (or kernel objects); The reason given to us is a handle rather than a pointer, with only one purpose: "Safety";
Seemingly through the handle can do a lot of things, but generally put the handle to a function (usually a system function), we also end up difficult to understand more; In fact, the system doesn't believe us.
Whether it is a pointer or a handle, is just a small piece of data in memory (general structure description), Microsoft does not expose the structure of the handle details, guess it should include: real pointer address, access permissions settings, reference count, and so on.
Since CreateThread can return a handle, the thread belongs to "kernel object".
In fact, what process does not belong to the pipeline, they are equal in the arms of the system; At the same time, the system will run each thread at the same interval, but the interval is so small that it makes us mistakenly assume that the program is running continuously.
//threadbase.h<br> #pragma once#include <windows.h>classcthreadbase{ Public: Cthreadbase (void); ~cthreadbase (void); StaticDWORD WINAPI ThreadProc (PVOID pparam); Virtual voidRun () =0; voidStart ();Private: HANDLE m_hthread; DWORD M_dwthreadid;};
//ThreadBase.cpp#include"StdAfx.h"#include"ThreadBase.h"Cthreadbase::cthreadbase (void) {M_hthread= CreateThread (NULL,0, ThreadProc, This,create_suspended,&m_dwthreadid);} Cthreadbase::~cthreadbase (void) {CloseHandle (m_hthread);} DWORD WINAPI Cthreadbase::threadproc (PVOID pparam) {if(null!=pparam) {(Cthreadbase*) Pparam)Run (); } return 0;}voidCthreadbase::start () {resumethread (m_hthread);}
Reference documents:
Using CreateThread () to create multithreaded threads
CreateThread Usage Explanation
CreateThread instances of C + +