Methods of Delphi Thread synchronization

Source: Internet
Author: User

For more details, refer to: http://www.cnblogs.com/xumenger/p/4450659.html

or refer to the blog after

Four system kernel objects (events, mutexes, signals, timers) are the means of thread synchronization, which also shows the complexity of handling thread synchronization, but this is not all, and Windows Vista is beginning to add Condition variables (condition variables), Slim Reader-writer Locks (read-write lock) and other synchronization means.

However, the simplest and lightest (fastest) synchronization is criticalsection (critical section), but it does not belong to the system kernel object, and of course there is no handle, no tsecurityattributes This security attribute, which also causes it to not be used across processes, However, it is generally not necessary to cross-process when writing multi-threading, so criticalsection should be the most common means of synchronization.

I think it is necessary to understand this at this point: This attribute is generally present when building system kernel objects (tsecureattributes)

In the next multi-threaded subject to use some kernel objects, it is better to check the first, then encounter this attribute to give a nil, no need to bother.

Building events

function CreateEvent (  lpeventattributes:psecurityattributes; {!}  Bmanualreset:bool;  Binitialstate:bool;  Lpname:pwidechar): Thandle; stdcall;

Creating mutexes

function CreateMutex (  lpmutexattributes:psecurityattributes; {!}  Binitialowner:bool;  Lpname:pwidechar): Thandle; stdcall;

Signal creation

function CreateSemaphore (  lpsemaphoreattributes:psecurityattributes; {!}  Linitialcount:longint;  Lmaximumcount:longint;  Lpname:pwidechar): Thandle; stdcall;

Setting up a wait timer

function CreateWaitableTimer (  lptimerattributes:psecurityattributes; {!}  Bmanualreset:bool;  Lptimername:pwidechar): Thandle; stdcall;

  

The above four system kernel objects (events, mutexes, signals, timers) are the means of thread synchronization, which can also be seen to handle the complexity of thread synchronization, but this is not all, Windows Vista began to add Condition variables (condition variable), Slim Reader-writer Locks (read-write lock) and other synchronization means.

However, the simplest and lightest (fastest) synchronization is criticalsection (critical section), but it does not belong to the system kernel object, and of course there is no handle, no tsecurityattributes This security attribute, which also causes it to not be used across processes, However, it is generally not necessary to cross-process when writing multi-threading, so criticalsection should be the most common means of synchronization.

Methods of Delphi Thread synchronization

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.