[Diocp3-iocptask manual] Post and callback processing unit for multi-threaded tasks based on the IOCP engine

Source: Internet
Author: User

Description

Iocptask is a multi-threaded task delivery and processing unit based on IOCP engine, it is convenient to post the task to IOCP thread for unified scheduling and processing, is to imitate Qdac-qworker processing mode, support D7 above version.

"How to use"

Very simple to use, the following explains a more comprehensive approach:

procedure Postatask (pvtaskwork:tontaskwork;        Nil ;        = False;        = Rtsync); overload;

Parameters:

Pvtaskwork

callback function, procedure (pvtaskrequest:tiocptaskrequest) of object; Pvtaskrequest can access information such as incoming taskdata,strdata.

Pvtaskdata

Is the incoming data, the pointer type, can be any data, in the callback function can be obtained through the Pvtaskrequest object.

Pvruninmainthread:

Whether the callback function runs in the main thread, and takes into account some tasks that require access to the main thread interface, it needs to be run in the main thread.

Pvruntype:

In a synchronous way, two types of support, one is Rtsync is the use of thread synchronization mode, Rtpostmessage, using the message + event waiting mode. The message pattern takes into account the synchronization methods that can be taken when the synchronization method in the DLL is not available.

"Precautions"

When the main form is destroyed, many resources have been destroyed, and if there are tasks that require the main thread to be processed at this time, it may cause the main thread to hang, and the whole process will not end.

 destructor Tfrmmain.destroy;  begin   Flogtask.postatask (onlogmsg,  "  ABCD   "  100  );  Flogtask.active:  = false;  Flogtask.free; inherited Destroy;  end ; 

The above code will cause the program to fail to exit,Flogtask.postatask (onlogmsg, 'abcd', True, rtpostmessage); is the task delivered to the main thread, this time the main form is being destroyed, unable to postmessage the corresponding message (Synchronize way is also blocked) cause fmessageevent will continue to wait, It is important to note that the main thread task is not delivered when it is destroyed. You can disable the corresponding posting task in the destroy of the main form, at the beginning of the main form destructor, set enable: = FALSE; This way iocptask no longer handles any tasks, note that the first sentence of the destructor is not the Formdestory event of the form.

destructor Tfrmmain.destroy; begin   flogtask.enable:= false;  Iocptaskmanager.enable:= False;  .....  inherited Destroy; End;

[Diocp3-iocptask manual] Post and callback processing unit for multi-threaded tasks based on the IOCP engine

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.