#define_crt_secure_no_warnings#include"iostream"#include"windows.h"using namespacestd;voidNtapi poolthreadfunc (_inout_ ptp_callback_instance INSTANCE, _inout_opt_ PVOID Context) {cout<< GetCurrentThreadID () <<Endl;}voidNtapi poolthreadwork (_inout_ ptp_callback_instance INSTANCE, _inout_opt_ PVOID Context, _inout_ ptp_work Wo RK) {cout<< GetCurrentThreadID () <<Endl;}intMain () {//Create a thread pool//Ptp_pool ThreadPool = Createthreadpool (NULL);//Setthreadpoolthreadminimum (ThreadPool, 1);//Setthreadpoolthreadmaximum (ThreadPool, 3); //Initializing the EnvironmentTp_callback_environ te; Initializethreadpoolenvironment (&te);//Setthreadpoolcallbackpool (&te, ThreadPool); //Creating Threads//Trysubmitthreadpoolcallback (Poolthreadfunc, NULL, &te); //single work commit, run function asynchronously, one-time task//Trysubmitthreadpoolcallback (Poolthreadfunc, NULL, &te); //Trysubmitthreadpoolcallback (Poolthreadfunc, NULL, &te); //Trysubmitthreadpoolcallback (Poolthreadfunc, NULL, &te); //cleanup environment variables for thread pool//destroythreadpoolenvironment (&te); //Close the thread pool//Closethreadpool (threadPool);//SuspendThread (); //change thread status to hanging//ResumeThread (); //Resume thread state run /*Create a work item*/Ptp_work Pwk; Pwk= Createthreadpoolwork (Poolthreadwork, NULL, &te); //Submit a work item that can be submitted multiple timessubmitthreadpoolwork (PWK); submitthreadpoolwork (PWK); //waiting for work to endWaitforthreadpoolworkcallbacks (PWK,false); //Close Work Objectclosethreadpoolwork (PWK); System ("Pause"); return 0;}
Windows comes with a thread pool