// Threadtest. cpp: defines the console applicationProgram. // # Include "stdafx. H "# include <iostream> # include <windows. h> using namespace STD; handle hmutex; DWORD winapi fun (lpvoid lpparamter) {While (1) {waitforsingleobject (hmutex, infinite); cout <"Fun display! "<Endl; sleep (1000); releasemutex (hmutex) ;}} int _ tmain (INT argc, _ tchar * argv []) {handle hthread = createthread (null, 0, fun, null, 0, null); hmutex = createmutex (null, false, l "screen"); // This function is used to create an exclusive resource, the first parameter can be set to null, the second parameter specifies whether the resource belongs to the process that created it, and the third parameter specifies the Resource Name. // Create a resource closehandle (hthread) That is named screen and belongs to the process that creates it; while (1) {waitforsingleobject (hmutex, infinite ); // The first parameter specifies the handle of the requested resource, and the second parameter is generally set to infinite, indicating that if the requested resource is not applied for, it will wait until the resource is reached. // if it is set to 0, it indicates that the system will return if no resource is available. You can also specify how long it will wait to return, in the unit of 1‰ seconds. Cout <"main display! "<Endl; sleep (1000); releasemutex (hmutex); // This function is used to release an exclusive resource. Once a process releases this resource, it no longer belongs to it, if you want to use it again, you need to apply for the resource again .} return 0 ;}