Add the following to the winmain function in the project file:
Code (This code runs in bcb6.0 ):
Handle hmutex = createmutex (null, false, "process ");
If (getlasterror () = error_already_exists)
{
Closehandle (hmutex );
MessageBox (Application->
In Windows, the program prevents multiple common methods:1) Use the findwindow API function.Locate the window title (or/and class name)ProgramWhether it is running. If it is found, it indicates that the program is running, and you can exit the
HANDLE CreateThread (lpsecurity_attributes lpthreadattributes,//SD: Thread-safe-related properties, normally nullsize_t Dwstacksize,//initialstacksize: The size of the initialization stack for the new thread, which can be set to
Usage of 1.WaitForSingleObject
DWORD
WaitForSingleObject (
HANDLE Hhandle,
DWORD dwmilliseconds
);
The parameter hhandle is a handle to an event, and the second parameter, Dwmilliseconds, is the time interval. If the
"Copyright Notice: respect for the original, reproduced please retain the source: blog.csdn.net/shallnet or .../gentleliu, the article is for learning communication only, do not use for commercial purposes"in the previous section, when it comes to
Thread SynchronizationWhen using multiple threads in a program, there are generally few threads that can perform completely independent operations during their lifetimes. There are more cases where some threads do some processing, and other threads
Windows critical section, kernel event, mutex, semaphore. Critical section, kernel event, mutex, semaphore, all can complete the thread synchronization, here put their respective function call, structure definition, as well as apply the situation to
The following are from: http://blog.csdn.net/morewindows/article/details/7470936The use of critical section CS and event events in the classic thread synchronization problem is described earlier. This article describes the use of mutex mutex to
The first of the CreateMutexfunction function: Create mutex (note vs. event creation function)Function Prototypes:HANDLE CreateMutex (Lpsecurity_attributeslpmutexattributes,Boolbinitialowner,Lpctstrlpname);Function Description:The first parameter
What are thread-safe classes and functions that can be called by multiple threads without the occurrence of data-disordered classes and functions called thread-safe classes and functions, the root cause of thread insecurity first is the shared
Multithreading synchronization method now popular process thread synchronous mutex control mechanism, in fact, is the most primitive and basic 4 methods implemented: 1 Critical Zone : Through the serialization of multithreading to access public
This article is a continuation of the 14th chapter of the "DOS to Win32" series of the following, which is recommended for review before reading.
As the sweet incense said, command-line arguments are ubiquitous in windows, but generally do not feel,
Inter-process Communication introduction1 , several inter-process communication methods# pipe: A pipe is a half-duplex mode of communication in which data can only flow in one direction and can only be used between processes that have affinity. A
// The project references this unit to prevent multiple instances from appearing at the same time.Unit multinst;
Interface
Uses Windows, messages, sysutils, classes, forms;
Implementation
ConstStr_unique = '{2be6d96e-827f-4bf9-b33e-8740412cde96
// Use mutex objects to synchronize threads
# Include
# Include
DWORD winapi threadpro (lpvoid lpparameter );
DWORD winapi threadpro1 (lpvoid lpparameter );
Int num = 100;
Handle hmutex;
Int main ()
{
// The mutex object contains one used
In the ApplicationProgramOne advantage of using multiple threads is that each thread can be executed asynchronously. For Windows applications, time-consuming tasks can be executed in the background, so that the application windows and controls
1.1 Process Synchronization Mechanism
(1) atomic operation: the so-called atomic operation means that the operation will never be interrupted by any other task or event before execution is completed. That is to say, it is the smallest execution unit,
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.