CN114443010A - Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium - Google Patents

Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium Download PDF

Info

Publication number
CN114443010A
CN114443010A CN202011235774.4A CN202011235774A CN114443010A CN 114443010 A CN114443010 A CN 114443010A CN 202011235774 A CN202011235774 A CN 202011235774A CN 114443010 A CN114443010 A CN 114443010A
Authority
CN
China
Prior art keywords
asynchronous
execution unit
task
asynchronous task
task execution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011235774.4A
Other languages
Chinese (zh)
Inventor
周志刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN202011235774.4A priority Critical patent/CN114443010A/en
Publication of CN114443010A publication Critical patent/CN114443010A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Abstract

A method, a device, an electronic device and a storage medium for designing an asynchronous task gasket based on an asynchronous event are provided, wherein the method comprises the following steps: designing a basic execution unit at the bottom layer of a program; carrying out asynchronous logic abstract processing on the basic execution unit to obtain a first asynchronous task execution unit; acquiring an asynchronous event to be executed on the program; combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit; compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit; writing an asynchronous task gasket on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit; executing the asynchronous event on the fourth asynchronous task execution unit. The method and the device can greatly reduce the burden of developers, improve the correctness of the program and increase the robustness of the program.

Description

Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium
Technical Field
The invention belongs to the technical field of asynchronous tasks, and particularly relates to an asynchronous task gasket design method and device based on asynchronous events, electronic equipment and a storage medium.
Background
For some programs written by programmers, in order to improve the performance of the program, the programmers use an asynchronous programming mode to improve the efficiency of the program, so asynchronous notification uses an event mode to notify the caller. However, in the asynchronous use process, multiple threads can easily operate on one data or one file at the same time, and the problem of program crash is caused. For example, when a file is read by using asynchronous logic and then a thread is used to decrypt the content of the file, the decryption process is executed by an asynchronous thread, and it is desired that the decrypted data is exposed by the same thread, and so on, the 2 operations are all executed asynchronously. Due to asynchronous execution logic, 2 operations cannot be guaranteed to be in the same thread, and if the operations are not in the same thread, multiple threads can be decrypted and used simultaneously, so that a program problem is caused.
The conventional solution to the above problem needs a person writing a function to secure a thread by himself, for example, 2 operations are combined into one operation to be executed, or 2 operations are delivered to the same thread to be executed, that is, the conventional solution gives the correctness of the function to a developer to avoid, and the security is secured in a higher layer, so that each user needs to know and use the correctness to avoid errors, which is troublesome.
Disclosure of Invention
In view of the above, the present invention provides an asynchronous task shim design method, apparatus, electronic device and storage medium based on asynchronous events that overcome or at least partially solve the above problems.
In order to solve the technical problem, the invention provides an asynchronous task gasket design method based on asynchronous events, which comprises the following steps:
designing a basic execution unit at the bottom layer of a program;
carrying out asynchronous logic abstract processing on the basic execution unit to obtain a first asynchronous task execution unit;
acquiring an asynchronous event to be executed on the program;
combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
compiling an asynchronous task gasket on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit;
executing the asynchronous event on the fourth asynchronous task execution unit.
Preferably, the step of performing asynchronous logic abstraction processing on the basic execution unit to obtain the first asynchronous task execution unit includes:
designing an execution unit class executoraunit on the basic execution unit;
defining a pure virtual interface virtual void add in the execution unit class executoraunit;
the pure virtual interface virtual void add acquires all asynchronous execution tasks in the asynchronous execution task queue;
the pure virtual void add encapsulates all the asynchronous execution tasks;
the basic execution unit acquires all the asynchronous execution tasks;
and the basic execution unit stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
Preferably, the acquiring all the asynchronously executed tasks in the asynchronously executed task queue by the pure virtual interface virtual void add includes the steps of:
the pure virtual void add provides a parameter Function;
the parameter Function acquires all parameters in the asynchronous execution task queue and corresponding asynchronous execution tasks;
and the parameter Function packs all the parameters and all the corresponding asynchronous execution tasks to obtain a Function object.
Preferably, before the pure virtual void add provides the parameter Function, the method further includes the steps of:
presetting an empty queue queueUnit;
acquiring the asynchronous execution task;
and storing all the asynchronous execution tasks into the empty queue queueUnit according to a preset sequence to obtain the asynchronous execution task queue.
Preferably, the step of combining the asynchronous event into the first asynchronous task execution unit and obtaining a second asynchronous task execution unit comprises the steps of:
designing an event unit class EventUnit on the first asynchronous task execution unit;
defining an event thread running interface void runlnEventThread in the event unit class EventUnit;
acquiring a thread where the first asynchronous task execution unit is located;
judging whether a pointer fn of the event thread running interface void runlneventThread is null or not;
if yes, the asynchronous event is not executed;
if not, judging whether the asynchronous event is executed in the thread;
if yes, executing the asynchronous event;
and if not, adding the asynchronous event into the first asynchronous task execution unit to obtain the second asynchronous task execution unit.
Preferably, the writing of the universal task asynchronous interface on the second asynchronous task execution unit and the obtaining of the third asynchronous task execution unit include:
acquiring a first template parameter template < typename Request >;
writing a Virtual function interface (Virtual Future) on the second asynchronous task execution unit;
acquiring an asynchronous execution task and corresponding parameters thereof through the Virtual function interface;
encapsulating the asynchronous execution task and the corresponding parameter thereof by using the first template parameter template < typename Request >;
and obtaining the third asynchronous task execution unit.
Preferably, the writing of the asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit includes:
acquiring a second template parameter template < typename Response >;
installing the second template parameter template < type Request > on the third asynchronous task execution unit;
writing a constructor safe on the third asynchronous task execution unit;
writing execution logic of the asynchronous task execution unit on the second template parameter template < type Response >;
and obtaining the fourth asynchronous task execution unit.
The invention also provides an asynchronous task gasket design device based on asynchronous events, which comprises:
the design module is used for designing a basic execution unit at the bottom layer of a program;
the abstract module is used for carrying out asynchronous logic abstract processing on the basic execution unit and obtaining a first asynchronous task execution unit;
the acquisition module is used for acquiring the asynchronous event to be executed on the program;
the combining module is used for combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
the first compiling module is used for compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
and the second compiling module is used for compiling the asynchronous task gasket on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit.
The present invention also provides an electronic device, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the asynchronous event based asynchronous task shim design method as described in any one of the above.
The present invention also provides a storage medium storing a computer program which, when executed by a processor, is capable of implementing the asynchronous task shim design method based on asynchronous events as described in any of the above.
One or more technical solutions in the embodiments of the present invention have at least the following technical effects or advantages:
according to the asynchronous task gasket design method and device based on the asynchronous event, the electronic device and the storage medium, the asynchronous task gasket running on the bottom layer is written, the gasket is responsible for the thread correctness of the program, developers do not need to care which thread the task is executed on, the asynchronous task gasket can be randomly delivered to different threads, and the bottom layer gasket helps the developers to finish the safety related problems of the threads, so that the asynchronous task gasket is transparent to the developers, the burden of the developers can be greatly reduced, the correctness of the program is improved, and the robustness of the program is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on the drawings without creative efforts.
FIG. 1 is a schematic flowchart of an asynchronous task shim design method based on asynchronous events according to an embodiment of the present invention;
FIG. 2 is a schematic structural diagram of an asynchronous task shim designing apparatus based on asynchronous events according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a storage medium according to an embodiment of the present invention.
Detailed Description
The present invention will be described in detail below with reference to specific embodiments and examples, and the advantages and various effects of the present invention will be more clearly apparent therefrom. It will be understood by those skilled in the art that these specific embodiments and examples are for the purpose of illustrating the invention and are not to be construed as limiting the invention.
Throughout the specification, unless otherwise specifically noted, terms used herein should be understood as having meanings as commonly used in the art. Accordingly, unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. If there is a conflict, the present specification will control.
Unless otherwise specifically stated, various raw materials, reagents, instruments, equipment and the like used in the present invention are commercially available or can be prepared by existing methods.
Referring to fig. 1, in an embodiment of the present application, the present invention provides an asynchronous task shim design method based on asynchronous events, where the method includes the steps of:
s1: designing a basic execution unit at the bottom layer of a program;
s2: carrying out asynchronous logic abstract processing on the basic execution unit to obtain a first asynchronous task execution unit;
s3: acquiring an asynchronous event to be executed on the program;
s4: combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
s5: compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
s6: writing an asynchronous task gasket on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit;
s7: executing the asynchronous event on the fourth asynchronous task execution unit.
In the embodiment of the application, when based on events
When a gasket of an asynchronous task is designed, firstly, a basic execution unit is designed at the bottom layer of a program, then, the basic execution unit is subjected to asynchronous logic abstraction processing, and a first asynchronous task execution unit is obtained; then, acquiring an asynchronous event to be executed on the program, combining the asynchronous event into the first asynchronous task execution unit, and obtaining a second asynchronous task execution unit; then, a universal task asynchronous interface is written on the second asynchronous task execution unit to obtain a third asynchronous task execution unit, an asynchronous task gasket is written on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit, and then the asynchronous event is executed on the fourth asynchronous task execution unit.
In the embodiment of the application, the asynchronous task gasket running at the bottom layer is compiled by the asynchronous event-based asynchronous task gasket design method, the gasket is responsible for the thread correctness of a program, developers can randomly post different threads, and the bottom layer gasket helps the developers to finish the safety related problems of the threads, so that the gasket acts transparently to the developers, the burden of the developers can be greatly reduced, the correctness of the program is improved, and the robustness of the program is improved.
In this embodiment of the present application, the performing asynchronous logical abstraction processing on the basic execution unit and obtaining the first asynchronous task execution unit in step S2 includes the steps of:
designing an execution unit class executoraunit on the basic execution unit;
defining a pure virtual interface virtual void add in the execution unit class executoraunit;
the pure virtual interface virtual void add acquires all asynchronous execution tasks in the asynchronous execution task queue;
the pure virtual void add encapsulates all the asynchronous execution tasks;
the basic execution unit acquires all the asynchronous execution tasks;
and the basic execution unit stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
In this embodiment of the present application, when performing asynchronous logic abstraction processing on the basic execution unit and obtaining a first asynchronous task execution unit, specifically, an execution unit class executunit, specifically a class executunit, is first designed on the basic execution unit, and a pure virtual interface virtual add is defined in the execution unit class executunit, specifically, the pure virtual interface virtual add (Function < void ()) is defined as 0; then the pure virtual interface virtuaI void add acquires all asynchronous execution tasks in the asynchronous execution task queue and packages all the asynchronous execution tasks; and then the basic execution unit acquires all the asynchronous execution tasks, stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
In the embodiment of the application, the asynchronous task gasket design method based on the asynchronous event performs asynchronous logic abstraction processing on the basic execution unit, so as to obtain the first asynchronous task execution unit, and performs subsequent asynchronous event combination operation based on the first asynchronous task execution unit, so that the burden of developers can be greatly reduced.
In this embodiment of the present application, the acquiring all the asynchronously executed tasks in the asynchronously executed task queue by the pure virtual interface virtual void add includes the following steps:
the pure virtual void add provides a parameter Function;
the parameter Function acquires all parameters in the asynchronous execution task queue and corresponding asynchronous execution tasks;
and the parameter Function packs all the parameters and all the corresponding asynchronous execution tasks to obtain a Function object.
In this embodiment of the present application, when the virtual interface add acquires all the asynchronously executed tasks in the asynchronously executed task queue, first, the virtual interface virtual add provides a parameter Function, and the parameter Function acquires all the parameters in the asynchronously executed task queue and the asynchronously executed tasks corresponding to the parameters; and then the parameter Function packs all the parameters and all the asynchronous execution tasks corresponding to the parameters to obtain a Function object.
In this embodiment of the present application, the asynchronous task gasket design method based on asynchronous events obtains all asynchronous execution tasks in an asynchronous execution task queue through a virtual interface add, encapsulates all asynchronous execution tasks, and stores all asynchronous execution tasks in a subsequent basic execution unit to obtain the first asynchronous task execution unit operation. The burden of developers can be reduced, and the method is very convenient.
In this embodiment of the present application, before the pure virtual void add provides the parameter Function, the method further includes the steps of:
presetting an empty queue queueUnit;
acquiring the asynchronous execution task;
and storing all the asynchronous execution tasks into the empty queue queueUnit according to a preset sequence to obtain the asynchronous execution task queue.
In this embodiment, the asynchronous execution task queue is further required to be obtained before the parameter Function is provided by the virtual void add. Specifically, an empty queue queueUnit is preset, specifically std: : deque < Function > queueUnit _; then acquiring the asynchronous execution task; and then storing all the asynchronous execution tasks into the empty queue queueUnit according to a preset sequence to obtain the asynchronous execution task queue.
In the embodiment of the application, the asynchronous task gasket design method based on the asynchronous event stores all the asynchronous execution tasks according to the preset sequence by presetting an empty queue queueUnit and obtains the asynchronous execution task queue, and the integrity and the orderliness are good.
In this embodiment of the present application, the step S4 of combining the asynchronous event into the first asynchronous task execution unit and obtaining a second asynchronous task execution unit includes the steps of:
designing an event unit class EventUnit on the first asynchronous task execution unit;
defining an event thread running interface void runlnEventThread in the event unit class EventUnit;
acquiring a thread where the first asynchronous task execution unit is located;
judging whether a pointer fn of the event thread running interface void runlneventThread is null or not;
if yes, the asynchronous event is not executed;
if not, judging whether the asynchronous event is executed in the thread;
if yes, executing the asynchronous event;
and if not, adding the asynchronous event into the first asynchronous task execution unit to obtain the second asynchronous task execution unit.
In this embodiment of the present application, when the asynchronous event is combined into the first asynchronous task execution unit and a second asynchronous task execution unit is obtained, an event unit class EventUnit, specifically a class EventUnit, is first designed on the first asynchronous task execution unit, and then an event thread running interface void runeventthread, specifically a void runeventthread (Function < void () > fn) is defined in the event unit class EventUnit; then obtaining the thread where the first asynchronous task execution unit is located, and judging whether a pointer (fn) of the event thread running interface is empty or not; when the judgment result is yes, the asynchronous event is not executed; when the judgment is negative, judging whether the asynchronous event is executed in the thread; when the judgment result is yes, executing the asynchronous event; and if not, adding the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit.
In the embodiment of the present application, the asynchronous task gasket design method based on the asynchronous event provided by the present invention is good in robustness by determining whether a pointer fn of the event thread running interface void runlnEventThread is null and determining whether the asynchronous event is being executed in the thread, thereby implementing an operation of adding the asynchronous event to the first asynchronous task execution unit and obtaining the second asynchronous task execution unit.
In this embodiment of the present application, the writing of the generic task asynchronous interface on the second asynchronous task execution unit and obtaining the third asynchronous task execution unit in step S5 includes the steps of:
acquiring a first template parameter template < typename Request >;
installing the first template parameter template < type Request > on the second asynchronous task execution unit;
writing a Virtual function interface (Virtual Future) on the second asynchronous task execution unit;
acquiring an asynchronous execution task and corresponding parameters thereof through the Virtual function interface;
encapsulating the asynchronous execution task and the corresponding parameter thereof by using the first template parameter template < typename Request >;
and obtaining the third asynchronous task execution unit.
In this embodiment of the present application, when a universal task asynchronous interface is written on the second asynchronous task execution unit and a third asynchronous task execution unit is obtained, first, a first template parameter template < type Request > is obtained, and a pure Virtual function interface Virtual function is written on the second asynchronous task execution unit, specifically, the Virtual function interface Virtual < Response > op (Request) is 0; then, acquiring an asynchronous execution task and corresponding parameters thereof through the Virtual function interface Virtual Future; and then, encapsulating the asynchronous execution task and the corresponding parameters thereof by using the first template parameter template < typeparameter Request > to obtain the third asynchronous task execution unit.
In the embodiment of the application, the asynchronous task gasket design method based on the asynchronous event encapsulates the asynchronous execution task and the corresponding parameter thereof through the first template parameter template < type Request > and obtains the third asynchronous task execution unit, so that the process of constructing the third asynchronous task execution unit is saved.
In this embodiment of the present application, the writing of an asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit in step S6 includes the steps of:
acquiring a second template parameter template < type Response >;
installing the second template parameter template < type Request > on the third asynchronous task execution unit;
writing a constructor safe on the third asynchronous task execution unit;
writing execution logic of the asynchronous task execution unit on the second template parameter template < type Response >;
and obtaining the fourth asynchronous task execution unit.
In this embodiment of the present application, when an asynchronous task shim is written on the third asynchronous task execution unit and a fourth asynchronous task execution unit is obtained, first, a second template parameter template < type Response >, specifically template < type Response >, a constructor save, specifically an ExecutorSafe (eventemet eu) is written on the second template parameter template < type Response >, and then, an execution logic of the asynchronous task execution unit, such as Virtual Future < Response > operation (request), is written on the second template parameter template < type Response >.
In the embodiment of the present application, in the asynchronous task gasket design method based on the asynchronous event, the execution logic of the asynchronous task execution unit is written by the second template parameter template < type Response > and the fourth asynchronous task execution unit is obtained, so that the process of constructing the fourth asynchronous task execution unit is saved.
Referring to fig. 2, in an embodiment of the present application, the present invention further provides an asynchronous task shim designing apparatus based on asynchronous events, where the apparatus includes:
a design module 10 for designing a basic execution unit at a program bottom layer;
the abstraction module 20 is configured to perform asynchronous logical abstraction on the basic execution unit to obtain a first asynchronous task execution unit;
an obtaining module 30, configured to obtain an asynchronous event to be executed on the program;
a combining module 40, configured to combine the asynchronous event into the first asynchronous task execution unit and obtain a second asynchronous task execution unit;
the first compiling module 50 is used for compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
and a second writing module 60, configured to write an asynchronous task shim on the third asynchronous task execution unit and obtain a fourth asynchronous task execution unit.
In the embodiment of the present application, the asynchronous task gasket design device based on asynchronous events provided by the present invention can execute the asynchronous task gasket design method based on asynchronous events provided by the present invention.
Referring now to FIG. 3, a schematic diagram of an electronic device 100 suitable for implementing embodiments of the present disclosure is shown, the electronic device 100 being capable of implementing the asynchronous event based asynchronous task shim design method as described in any of the above. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., car navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 3, the electronic device 100 may include a processing means (e.g., a central processing unit, a graphic processor, etc.) 101 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)102 or a program loaded from a storage means 108 into a Random Access Memory (RAM) 103. In the RAM 103, various programs and data necessary for the operation of the electronic apparatus 100 are also stored. The processing device 101, the ROM102, and the RAM 103 are connected to each other via a bus 104. An input/output (I/O) interface 105 is also connected to bus 104.
Generally, the following systems may be connected to the I/0 interface 105: input devices 106 including, for example, a touch screen, touch pad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; an output device 107 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 108 including, for example, magnetic tape, hard disk, etc.; and a communication device 109. The communication means 109 may allow the electronic device 100 to communicate wirelessly or by wire with other devices to exchange data. While the figures illustrate an electronic device 100 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, the processes described above with reference to the flow diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 109, or installed from the storage means 108, or installed from the ROM 102. The computer program, when executed by the processing device 101, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
Referring now to FIG. 4, there is shown a schematic block diagram of a computer-readable storage medium suitable for use in implementing embodiments of the present disclosure, the computer-readable storage medium storing a computer program that, when executed by a processor, is capable of implementing an asynchronous event based asynchronous task shim design method as described in any of the above.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor device, system, or apparatus, or a combination of any of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution apparatus, system, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution apparatus, system, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring at least two internet protocol addresses; sending a node evaluation request comprising the at least two internet protocol addresses to node evaluation equipment, wherein the node evaluation equipment selects the internet protocol addresses from the at least two internet protocol addresses and returns the internet protocol addresses; receiving an internet protocol address returned by the node evaluation equipment; wherein the obtained internet protocol address indicates an edge node in the content distribution network.
Alternatively, the computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receiving a node evaluation request comprising at least two internet protocol addresses; selecting an internet protocol address from the at least two internet protocol addresses; returning the selected internet protocol address; wherein the received internet protocol address indicates an edge node in the content distribution network.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a limitation of the unit itself, for example, the first retrieving unit may also be described as a "unit for retrieving at least two internet protocol addresses".
It should be understood that portions of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof.
According to the asynchronous task gasket design method and device based on the asynchronous events, the electronic device and the storage medium, the asynchronous task gasket running at the bottom layer is compiled, the gasket is responsible for the thread correctness of the program, developers do not need to care which thread the task executes, the asynchronous task gasket can be randomly delivered to different threads, and the bottom layer gasket helps the developers to finish the safety related problems of the threads, so that the gasket is transparent to the developers, the burden of the developers can be greatly reduced, the correctness of the program is improved, and the robustness of the program is improved.
Finally, it should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. The terms "first" and "second" in this application are to be understood as terms.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A method for designing asynchronous task shim based on asynchronous events is characterized by comprising the following steps:
designing a basic execution unit at the bottom layer of a program;
carrying out asynchronous logic abstract processing on the basic execution unit to obtain a first asynchronous task execution unit;
acquiring an asynchronous event to be executed on the program;
combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
writing an asynchronous task gasket on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit;
executing the asynchronous event on the fourth asynchronous task execution unit.
2. The asynchronous task shim design method based on asynchronous events as claimed in claim 1, wherein the step of performing asynchronous logic abstraction on the basic execution unit and obtaining a first asynchronous task execution unit comprises the steps of:
designing an execution unit class executoraunit on the basic execution unit;
defining a pure virtual interface virtual void add in the execution unit class ExecutorUnit;
the pure virtual interface virtual void add acquires all asynchronous execution tasks in the asynchronous execution task queue;
the pure virtual void add encapsulates all the asynchronous execution tasks;
the basic execution unit acquires all the asynchronous execution tasks;
and the basic execution unit stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
3. The asynchronous task gasket design method based on asynchronous events as recited in claim 2, wherein the step of obtaining all the asynchronously executed tasks in the asynchronously executed task queue by the pure virtual interface virtual void add comprises the steps of:
the pure virtual void add provides a parameter Function;
the parameter Function acquires all parameters in the asynchronous execution task queue and corresponding asynchronous execution tasks;
and packaging all the parameters and all the corresponding asynchronous execution tasks by the parameter Function to obtain a Function object.
4. The asynchronous task shim design method based on asynchronous events as claimed in claim 3, further comprising, before the pure virtual void add provides parameter Function, the steps of:
presetting an empty queue queueUnit;
acquiring the asynchronous execution task;
and storing all the asynchronous execution tasks into the empty queue queueUnit according to a preset sequence to obtain the asynchronous execution task queue.
5. The asynchronous task shim design method based on asynchronous events as claimed in claim 1, wherein the step of integrating the asynchronous event into the first asynchronous task execution unit and obtaining a second asynchronous task execution unit comprises the steps of:
designing an event unit class EventUnit on the first asynchronous task execution unit;
defining an event thread running interface void runInEventThread in the event unit class EventUnit;
acquiring a thread where the first asynchronous task execution unit is located;
judging whether a pointer fn of the event thread running interface void runInEventThread is empty or not;
if yes, the asynchronous event is not executed;
if not, judging whether the asynchronous event is executed in the thread;
if yes, executing the asynchronous event;
and if not, adding the asynchronous event into the first asynchronous task execution unit to obtain the second asynchronous task execution unit.
6. The asynchronous task gasket design method based on asynchronous events as recited in claim 1, wherein said programming a generic task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit comprises the steps of:
acquiring a first template parameter template < typename Request >;
installing the first template parameter template < type Request > on the second asynchronous task execution unit;
writing a Virtual function interface (Virtual Future) on the second asynchronous task execution unit;
acquiring an asynchronous execution task and corresponding parameters thereof through the Virtual function interface;
encapsulating the asynchronous execution task and the corresponding parameter thereof by using the first template parameter template < typename Request >;
and obtaining the third asynchronous task execution unit.
7. The asynchronous task shim design method based on asynchronous events as claimed in claim 1, wherein said writing an asynchronous task shim on the third asynchronous task execution unit and getting a fourth asynchronous task execution unit comprises the steps of:
acquiring a second template parameter template < type Response >;
installing the second template parameter template < type Request > on the third asynchronous task execution unit;
writing a constructor safe on the third asynchronous task execution unit;
writing execution logic of the asynchronous task execution unit on the second template parameter template < type Response >;
and obtaining the fourth asynchronous task execution unit.
8. An asynchronous task shim design apparatus based on asynchronous events, the apparatus comprising:
the design module is used for designing a basic execution unit at the bottom layer of the program;
the abstract module is used for carrying out asynchronous logic abstract processing on the basic execution unit and obtaining a first asynchronous task execution unit;
the acquisition module is used for acquiring the asynchronous event to be executed on the program;
the combining module is used for combining the asynchronous event into the first asynchronous task execution unit and obtaining a second asynchronous task execution unit;
the first compiling module is used for compiling a universal task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
and the second compiling module is used for compiling the asynchronous task gasket on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the asynchronous event based asynchronous task shim design method of any of claims 1-7.
10. A storage medium storing a computer program, wherein the computer program, when executed by a processor, is capable of implementing an asynchronous task shim design method based on asynchronous events according to any of claims 1-7.
CN202011235774.4A 2020-11-06 2020-11-06 Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium Pending CN114443010A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011235774.4A CN114443010A (en) 2020-11-06 2020-11-06 Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011235774.4A CN114443010A (en) 2020-11-06 2020-11-06 Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114443010A true CN114443010A (en) 2022-05-06

Family

ID=81361039

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011235774.4A Pending CN114443010A (en) 2020-11-06 2020-11-06 Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114443010A (en)

Similar Documents

Publication Publication Date Title
CN110865898B (en) Method, device, medium and equipment for converging crash call stack
CN114625481B (en) Data processing method and device, readable medium and electronic equipment
CN112395188B (en) Test-oriented software project development method and device, electronic equipment and storage medium
CN111079125A (en) Method and device for calling third-party library dynamic lifting authority by application program
CN114625536B (en) Video memory allocation method, device, medium and electronic equipment
CN110865846B (en) Application management method, device, terminal, system and storage medium
CN111324258B (en) Method, device, equipment and medium for generating contents of configuration items of multilevel pull-down menu
CN111414152B (en) Method, system, readable medium and electronic device for realizing business logic
CN110333843B (en) Method and device for realizing high-precision timer of virtual machine and electronic equipment
WO2020233170A1 (en) Information display method, apparatus and device, and medium
CN111324347A (en) Component construction method, device and system, page generation method, equipment and medium
CN114443010A (en) Asynchronous task gasket design method and device based on asynchronous event, electronic equipment and storage medium
US20220269622A1 (en) Data processing methods, apparatuses, electronic devices and computer-readable storage media
CN113391860B (en) Service request processing method and device, electronic equipment and computer storage medium
CN111290812B (en) Display method, device, terminal and storage medium of application control
CN111324336B (en) Method, device, terminal and storage medium for implementing dependency injection
CN110908860B (en) Java thread acquisition method and device, medium and electronic equipment
CN110764995B (en) Method, device, medium and electronic equipment for detecting file access abnormality
CN112732248A (en) Modularized software development method and device, electronic equipment and storage medium
CN111310175A (en) iOS application safety monitoring and protecting method and device based on plug-in
CN111625326A (en) Task pipeline execution method and device and electronic equipment
CN113448550B (en) Method and device for realizing collection management of classes, electronic equipment and computer medium
CN111125759A (en) Database login account shielding method and device and electronic equipment
CN111209739A (en) Electronic form, electronic device, storage medium, and electronic form verification method
CN112688863B (en) Gateway data processing method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination