Summary: All applications in Windows 95 are actually running in a threaded fashion. In designing multithreaded applications, it is sometimes necessary to maintain a certain synchronization relationship between threads in order to enable users to effectively control a thread running independently. In this paper, after a brief introduction of the concept of Windows 95 thread and its creation method, a control method of event synchronization is proposed, which is realized by the object of multithreading. Finally, the method of synchronizing event control between different applications is introduced, which makes it easy to control the synchronization events between different applications.
Sync Events Event
Object Win32
One, Introduction
Windows 95 is a multitasking, multi-threaded operating system in which each application is a process. Processes can create multiple concurrent threads (thread), while processes are also scheduled by the system in the form of the main thread (primarythread). The so-called thread is a basic unit of system scheduling, where the program threads appear as functions, and their code is part of the process code, and public information such as open tables is shared with the process and other threads that it derives from, sharing the process's global variables and files. The main thread is similar to a parent process in a UNIX system, and the thread is similar to a child process. The primary thread is also a thread, called the main thread, just to distinguish it from the thread it creates. Each thread runs independently relative to the main thread, and in order for the thread to respond to the user's control, it must control the running of the thread, such as the user can pause, terminate the operation of a thread, or change the condition of the thread running. In addition, there should be a certain synchronization control relationship between user control and thread running to ensure the user's effective control of the thread. A thread can respond differently to a user's control based on different conditions. For this purpose, you must use the system-supplied synchronization object (synchronization object), such as the event object. Writing multithreaded applications must use the Win32 API.
Second, the thread creation method
Call the CreateThread function in the Win32 API to create the thread. Hthread=createthread (Null,0,&teventwindow::threadfunc,this,0,&hthreadid); The first parameter sets the security property of the thread because it is used only for Windows NT , so do not set. The second parameter is 0 specifies that the thread uses the default stack size. The third parameter specifies the thread function, which starts at the entrance of the function, and when the function returns, it means that the thread terminates running. The fourth parameter is a parameter to the thread function and can be a pointer to any data type. The fifth parameter sets the build flag for the thread. Hthreadid holds the identification number of the thread. The thread function is defined as follows, the This parameter is a handle pointer to a thread-owned window, passed through the Thrdwin parameter, and the corresponding Loopfunc function is invoked with this pointer, and the thread's specific transaction is executed in this function.