MFC Events and Threads

Source: Internet
Author: User
Tags unique id

 HANDLE WINAPI CreateThread (__in_opt lpsecurity_attributes lpthreadattributes,//Pointer to security_attributes, refers to a new thread   Fixed security description __in size_t dwstacksize,//Initialize thread stack size __in lpthread_start_routine lpstartaddress,//The address start function that the thread function points to __in_opt lpvoid Lpparameter,//parameter passed to thread function __in DWORD dwcreationflags,//flag for thread __out_opt Lpdword lpthread ID//The ID of the system assigned to the thread); The 
----The first parameter is a security attribute, which is generally set to NULL, using the default security attribute. When we want this thread to have another child process, it can change its properties.  
----The second parameter is the thread stack size, which is typically set to 0, which is the same stack size as the application, which is the same length as the thread that was created. and its length will automatically grow as needed.  
----The third parameter, and the most important one, is a pointer to the function name, or the function name  
---- The fourth parameter is the argument you need to pass to the thread function, typically a pointer to the struct. This parameter is set to NULL when no arguments are passed.  
----The fifth parameter, passing some flags about the thread, and if it is create_suspended, create a suspended thread, that is, the thread itself has been created, and its stack has been created.
But this thread will not be allocated to CPU time, only if the ResumeThread function is called, and of course, you can call the SuspendThread function to suspend the thread again. If the flag is 0, then once the thread is established, the thread function is called immediately. General transmission is 0.  
----The sixth parameter is the unique ID flag   assigned to this thread by the system;

The event object is like a switch: it has only two states---on and off. When an event is in the "on" state, we call it "signaled" otherwise called "no signal". You can create an event object in the execution function of a thread, then observe its state, and if it is "no signal", let the thread sleep, so that the thread consumes less CPU time.

The function that produces the event object is as follows:

HANDLE CreateEvent (

Lpsecurity_attributes lpeventattributes,//SD
BOOL bManualReset,//Reset type
BOOL Binitialstate,//Initial state
LPCTSTR lpname//object name
);
The function creates an event synchronization object that returns a handle to the newly generated object if the CreateEvent call succeeds, otherwise returns NULL.

Parameter description:
Lpeventattributes is generally null


Whether the event created by bManualReset is auto reset or manual reset. If true, manual reset, once the event is set to signaled, it will wait until the ResetEvent () API is called to return to no signal.   If the false,event is set to a signal, then when there is a wait to its thread, the event is automatically reset and becomes no signal. If you want Windows to automatically revert the status of the event to "no signal" for you after each call to WaitForSingleObject, you must set this parameter to False, otherwise you must call the ResetEvent function every time to clear the signal of the event.


Binitialstate initial state, true, signaled, false no signal
The name of the Lpname event object. You may use it in the OpenEvent function.

Control the thread by judging the event by WaitForSingleObject or GetOverlappedResult.

MFC Events and Threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.