An asynchronous event-based asynchronous task shim design method and device, electronic equipment and storage medium
By designing asynchronous task pads at the program's underlying level, the problem of program crashes caused by multi-threaded operations in asynchronous programming is solved, thread safety management is achieved, the burden on developers is reduced, and the correctness and robustness of the program are improved.
Patent Information
- Application Number
- CN202011235774.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-06
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2040-11-06
AI Technical Summary
In asynchronous programming, the problem of multiple threads operating on the same data or file can cause program crashes. Traditional solutions rely on developers to ensure thread safety, which increases the development difficulty.
The basic execution unit is designed at the program level. Asynchronous logic is abstracted and processed, asynchronous task pads are written to ensure thread correctness, and thread safety management is completed at the underlying level, so that developers do not need to care about which thread the task is executed on.
It reduces the burden on developers, improves the correctness and robustness of programs, and ensures thread safety.
Smart Images

Figure CN114443010B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of asynchronous tasks, and particularly relates to an asynchronous task gasket design method and device based on asynchronous events, an electronic device and a storage medium. BACKGROUND
[0002] For some programs written by programmers, in order to improve the performance of the program, the programmer will use the mode of asynchronous programming to improve the efficiency of the program, so the asynchronous notification will use the mode of event to notify the caller. However, in the process of asynchronous use, it is easy to cause multiple threads to operate a data or a file at the same time, thereby causing the problem of program crash. For example, when an asynchronous logic is used to read a file, and then a thread is used to decrypt the content of the file, at this time, the decryption process is executed by an asynchronous thread, and it is hoped that the decrypted data is used by the same thread to display the data. The above two operations are asynchronous execution logic. Since it is asynchronous execution logic, it cannot be guaranteed that the two operations are in the same thread, and if they are not in the same thread, multiple threads will be used for decryption and use at the same time, thereby causing the program to malfunction.
[0003] The traditional solution to the above problem requires the person who writes the function to guarantee the safety of the thread, for example, the two operations are combined into one operation to execute, or the two operations are delivered to the same thread to execute, that is, the traditional solution gives the correctness of the function to the developer to avoid it, which guarantees the safety in the upper layer. Therefore, it is required that each user must understand and use correctly to avoid errors, which is troublesome. SUMMARY
[0004] In view of the above problems, the application provides an asynchronous task gasket design method and device based on asynchronous events, an electronic device and a storage medium, which can overcome the above problems or at least partially solve the above problems.
[0005] To solve the above technical problems, the application provides an asynchronous task gasket design method based on asynchronous events, which comprises the following steps:
[0006] designing a basic execution unit at the bottom of the program;
[0007] performing asynchronous logic abstraction processing on the basic execution unit to obtain a first asynchronous task execution unit;
[0008] obtaining an asynchronous event to be executed on the program;
[0009] combining the asynchronous event into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
[0010] writing a general task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit;
[0011] writing an asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit;
[0012] executing the asynchronous event on the fourth asynchronous task execution unit.
[0013] Preferably, the asynchronous logic abstraction processing on the base execution unit and obtaining a first asynchronous task execution unit comprises the steps of:
[0014] designing an execution unit class ExecutorUnit on the base execution unit;
[0015] defining a pure virtual interface virtual void add in the execution unit class ExecutorUnit;
[0016] the pure virtual interface virtual void add obtains all asynchronous execution tasks in an asynchronous execution task queue;
[0017] the pure virtual interface virtual void add encapsulates all the asynchronous execution tasks;
[0018] the base execution unit obtains all the asynchronous execution tasks;
[0019] the base execution unit stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
[0020] Preferably, the pure virtual interface virtual void add obtains all asynchronous execution tasks in an asynchronous execution task queue comprises the steps of:
[0021] the pure virtual interface virtual void add provides a parameter Function;
[0022] the parameter Function obtains all parameters and corresponding asynchronous execution tasks in the asynchronous execution task queue;
[0023] the parameter Function packs all the parameters and all the corresponding asynchronous execution tasks to obtain a Function object.
[0024] Preferably, before the pure virtual interface virtual void add provides a parameter Function, it further comprises the steps of:
[0025] presetting an empty queue queueUnit;
[0026] obtaining the asynchronous execution task;
[0027] storing all the asynchronous execution tasks in the queueUnit according to a preset order to obtain the asynchronous execution task queue.
[0028] 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:
[0029] designing an event unit class EventUnit on the first asynchronous task execution unit;
[0030] defining an event thread running interface void runlnEventThread in the event unit class EventUnit;
[0031] obtaining a thread on which the first asynchronous task execution unit runs;
[0032] judging whether a pointer fn of the event thread running interface void runlnEventThread is empty;
[0033] if yes, not executing the asynchronous event;
[0034] if no, judging whether the asynchronous event is being executed in the thread;
[0035] if yes, executing the asynchronous event;
[0036] if no, adding the asynchronous event into the first asynchronous task execution unit and obtaining the second asynchronous task execution unit.
[0037] Preferably, the step of writing a general task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit comprises the steps of:
[0038] obtaining a first template parameter template<typename Request>;
[0039] writing a pure virtual function interface Virtual Future on the second asynchronous task execution unit;
[0040] obtaining an asynchronous execution task and a corresponding parameter thereof through the pure virtual function interface Virtual Future;
[0041] encapsulating the asynchronous execution task and the corresponding parameter thereof by using the first template parameter template<typename Request>;
[0042] obtaining the third asynchronous task execution unit.
[0043] Preferably, the step of writing an asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit comprises the steps of:
[0044] obtaining a second template parameter template<typename Response>;
[0045] installing the second template parameter template<typename Request> on the third asynchronous task execution unit;
[0046] writing a constructor ExecutorSafe on the third asynchronous task execution unit;
[0047] writing an execution logic of the asynchronous task execution unit on the second template parameter template<typename Response>;
[0048] obtaining the fourth asynchronous task execution unit.
[0049] The application further provides an asynchronous task shim design device based on asynchronous events, which comprises:
[0050] a design module, configured to design a basic execution unit at a program bottom layer;
[0051] an abstraction module, configured to perform asynchronous logic abstraction processing on the basic execution unit and obtain a first asynchronous task execution unit;
[0052] an obtaining module, configured to obtain an asynchronous event to be executed on the program;
[0053] a combining module, configured to combine the asynchronous event to the first asynchronous task execution unit and obtain a second asynchronous task execution unit;
[0054] a first writing module, configured to write a general task asynchronous interface on the second asynchronous task execution unit and obtain a third asynchronous task execution unit;
[0055] a second writing module, configured to write an asynchronous task shim on the third asynchronous task execution unit and obtain a fourth asynchronous task execution unit.
[0056] The application further provides an electronic device, which comprises:
[0057] at least one processor; and,
[0058] a memory connected in communication with the at least one processor; wherein,
[0059] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the asynchronous event-based asynchronous task shim design method according to any one of the above.
[0060] The application further provides a storage medium storing a computer program, and the computer program is executed by a processor to implement the asynchronous event-based asynchronous task shim design method according to any one of the above.
[0061] The one or more technical solutions in the embodiments of the application have at least the following technical effects or advantages:
[0062] The application provides an asynchronous event-based asynchronous task shim design method and device, electronic equipment and a storage medium, which write an asynchronous task shim running at a bottom layer, and the shim is responsible for thread correctness of a program, and a developer does not need to care about execution of a task in which thread, and the developer can randomly deliver the task to different threads, and the bottom layer shim helps to complete thread safety related problems, so that the developer is transparent to the behavior, the burden of the developer can be greatly reduced, program correctness is improved, and program robustness is increased. BRIEF DESCRIPTION OF DRAWINGS
[0063] In order to more clearly illustrate the technical solutions in the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiments description. Obviously, the drawings in the following description are some embodiments of the application, and for those skilled in the art, other drawings can also be obtained from these drawings without creative labor.
[0064] Figure 1 is a flow diagram of an asynchronous event-based asynchronous task shim design method provided by an embodiment of the application;
[0065] Figure 2 is a structural diagram of an asynchronous event-based asynchronous task shim design device provided by an embodiment of the application;
[0066] Figure 3 is a structural diagram of an electronic equipment provided by an embodiment of the application;
[0067] Figure 4 is a structural diagram of a storage medium provided by an embodiment of the application. DETAILED DESCRIPTION
[0068] The advantages and various effects of the present application will be more clearly presented hereinafter with specific embodiments and examples. Those skilled in the art should understand that these embodiments and examples are used to illustrate the present application, but not to limit the present application.
[0069] Throughout the specification, unless otherwise specifically indicated, the terms used herein are understood to have the meanings commonly used in the art. Therefore, unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. If there is a contradiction, the present specification takes precedence.
[0070] Unless otherwise specifically indicated, various raw materials, reagents, instruments and equipment used in the present application can be purchased from the market or can be prepared by existing methods.
[0071] As Figure 1 In the embodiments of the present application, the present application provides an asynchronous task shim design method based on asynchronous events, which comprises the following steps:
[0072] S1: designing a basic execution unit at the bottom of a program;
[0073] S2: performing asynchronous logic abstraction processing on the basic execution unit to obtain a first asynchronous task execution unit;
[0074] S3: obtaining asynchronous events to be executed on the program;
[0075] S4: combining the asynchronous events into the first asynchronous task execution unit to obtain a second asynchronous task execution unit;
[0076] S5: writing a general task asynchronous interface on the second asynchronous task execution unit to obtain a third asynchronous task execution unit;
[0077] S6: writing an asynchronous task shim on the third asynchronous task execution unit to obtain a fourth asynchronous task execution unit;
[0078] S7: executing the asynchronous events on the fourth asynchronous task execution unit.
[0079] In the embodiments of the present application, when the event
[0080] In the design of the asynchronous task pad, first, a basic execution unit is designed at the bottom of a program, and then the basic execution unit is subjected to asynchronous logic abstraction processing to obtain a first asynchronous task execution unit; then, an asynchronous event to be executed on the program is obtained, and the asynchronous event is combined into the first asynchronous task execution unit to obtain a second asynchronous task execution unit; then, a general task asynchronous interface is written on the second asynchronous task execution unit to obtain a third asynchronous task execution unit, and an asynchronous task pad 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.
[0081] In the embodiment of the present application, the asynchronous task pad design method based on asynchronous events is provided, which compiles an asynchronous task pad running at the bottom. The pad is responsible for the thread correctness of the program, and the developer can arbitrarily deliver to different threads, and the bottom pad helps to complete the thread safety related problems, so that the behavior is transparent to the developer, which can greatly reduce the burden of the developer, improve the correctness of the program, and increase the robustness of the program.
[0082] In the embodiment of the present application, the step S2 of performing asynchronous logic abstraction processing on the basic execution unit to obtain a first asynchronous task execution unit comprises the steps of:
[0083] designing an execution unit class ExecutorUnit on the basic execution unit;
[0084] defining a pure virtual interface virtual void add in the execution unit class ExecutorUnit;
[0085] the pure virtual interface virtual void add obtains all asynchronous execution tasks in an asynchronous execution task queue;
[0086] the pure virtual interface virtual void add encapsulates all the asynchronous execution tasks;
[0087] the basic execution unit obtains all the asynchronous execution tasks;
[0088] the basic execution unit stores all the asynchronous execution tasks to obtain the first asynchronous task execution unit.
[0089] In the embodiment of the present application, when the asynchronous logic abstraction processing is performed on the basic execution unit and the first asynchronous task execution unit is obtained, specifically, first, an execution unit class ExecutorUnit is designed on the basic execution unit, specifically, class ExecutorUnit, and a pure virtual interface virtual void add is defined in the execution unit class ExecutorUnit, specifically, virtual void add(Function<void()>)=0; then the pure virtual interface virtual void add obtains all asynchronous execution tasks in an asynchronous execution task queue, and encapsulates all the asynchronous execution tasks; then the basic execution unit obtains all the asynchronous execution tasks, and the basic execution unit stores all the asynchronous execution tasks and obtains the first asynchronous task execution unit.
[0090] In the embodiment of the present application, the asynchronous task gasket design method based on asynchronous events provided by the present application performs asynchronous logic abstraction processing on the basic execution unit, thereby obtaining a first asynchronous task execution unit, and performs subsequent asynchronous event combination operation based on the first asynchronous task execution unit, which can greatly reduce the burden of the developer.
[0091] In the embodiment of the present application, the pure virtual interface virtual void add obtaining all asynchronous execution tasks in an asynchronous execution task queue comprises the following steps:
[0092] The pure virtual interface virtual void add provides a parameter Function.
[0093] The parameter Function obtains all parameters in the asynchronous execution task queue and corresponding asynchronous execution tasks.
[0094] The parameter Function packs all the parameters and all the corresponding asynchronous execution tasks to obtain a Function object.
[0095] In the embodiment of the present application, when the pure virtual interface virtual void add obtains all asynchronous execution tasks in an asynchronous execution task queue, first, the pure virtual interface virtual void add provides a parameter Function, the parameter Function obtains all parameters in the asynchronous execution task queue and corresponding asynchronous execution tasks; then the parameter Function packs all the parameters and all the corresponding asynchronous execution tasks to obtain a Function object.
[0096] In the embodiment of the present application, the asynchronous task pad design method based on asynchronous events provided by the present application acquires all asynchronous execution tasks in the asynchronous execution task queue through a pure virtual interface virtual void add, and encapsulates all asynchronous execution tasks, and the subsequent basic execution unit stores all asynchronous execution tasks to obtain the first asynchronous task execution unit operation. The burden of the developer can be reduced, which is very convenient.
[0097] In the embodiment of the present application, before the pure virtual interface virtual void add provides a parameter Function, the step of:
[0098] A preset empty queue queueUnit is provided.
[0099] The asynchronous execution task is acquired.
[0100] All asynchronous execution tasks are stored in the empty queue queueUnit according to a preset order to obtain the asynchronous execution task queue.
[0101] In the embodiment of the present application, when the pure virtual interface virtual void add provides a parameter Function, the asynchronous execution task queue needs to be obtained. Specifically, first, an empty queue queueUnit is preset, specifically std::deque <function>queueUnit; then obtaining the asynchronous execution tasks; and then storing all the asynchronous execution tasks into the empty queue queueUnit in a preset order to obtain the asynchronous execution task queue.
[0102] In the embodiments of the present application, the asynchronous task pad design method based on asynchronous events provided by the present application stores all the asynchronous execution tasks in a preset order by predefining an empty queue queueUnit and obtains the asynchronous execution task queue, which is complete and well-organized.
[0103] In the embodiments of the present application, the step of combining the asynchronous event into the first asynchronous task execution unit and obtaining the second asynchronous task execution unit in step S4 includes the steps of:
[0104] designing an event unit class EventUnit on the first asynchronous task execution unit;
[0105] defining an event thread running interface void runlnEventThread in the event unit class EventUnit;
[0106] obtaining a thread on which the first asynchronous task execution unit runs;
[0107] judging whether a pointer fn of the event thread running interface void runlnEventThread is empty;
[0108] if yes, not executing the asynchronous event;
[0109] if no, judging whether the asynchronous event is being executed in the thread;
[0110] if yes, executing the asynchronous event;
[0111] if no, adding the asynchronous event into the first asynchronous task execution unit and obtaining the second asynchronous task execution unit.
[0112] In the 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, first, an event unit class EventUnit is designed on the first asynchronous task execution unit, specifically class EventUnit, and then an event thread running interface void runlnEventThread is defined in the event unit class EventUnit, specifically void runlnEventThread(Function<void()>fn); Next, the thread on which the first asynchronous task execution unit is lined is obtained, and it is determined whether the pointer (fn) of the event thread running interface is empty; when it is determined to be yes, the asynchronous event is not executed; when it is determined to be no, it is determined whether the asynchronous event is being executed in the thread; when it is determined to be yes, the asynchronous event is executed; when it is determined to be no, the asynchronous event is added to the first asynchronous task execution unit and the second asynchronous task execution unit is obtained.
[0113] In the embodiment of the present application, the asynchronous task pad design method based on asynchronous events provided by the present application realizes the operation of adding the asynchronous event to the first asynchronous task execution unit and obtaining the second asynchronous task execution unit by judging whether the pointer fn of the event thread running interface void runlnEventThread is empty and judging whether the asynchronous event is being executed in the thread, and has good robustness.
[0114] In the embodiment of the present application, the step of writing a general task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit in step S5 includes the steps of:
[0115] obtaining a first template parameter template<typename Request>;
[0116] installing the first template parameter template<typename Request> on the second asynchronous task execution unit;
[0117] writing a pure virtual function interface Virtual Future on the second asynchronous task execution unit;
[0118] obtaining an asynchronous execution task and its corresponding parameters through the pure virtual function interface Virtual Future;
[0119] encapsulating the asynchronous execution task and its corresponding parameters using the first template parameter template<typename Request>;
[0120] obtaining the third asynchronous task execution unit.
[0121] In the embodiment of the present application, when a general 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 is obtained<template<typename Request> >, and a pure virtual function interface Virtual Future is written on the second asynchronous task execution unit, specifically, Virtual Future <response>Op(Request request) = 0; then get asynchronous execution task and its corresponding parameters through the pure virtual function interface Virtual Future; then use the first template parameter template <typenamerequest>The asynchronous execution task and the corresponding parameter are encapsulated to obtain the third asynchronous task execution unit.
[0122] In the embodiment of the present application, the asynchronous task shim design method based on asynchronous events provided by the present application encapsulates the asynchronous execution task and the corresponding parameter through a first template parameter template<typename Request> and obtains the third asynchronous task execution unit, thereby saving the process of constructing the third asynchronous task execution unit.
[0123] In the embodiment of the present application, the step of writing an asynchronous task shim on the third asynchronous task execution unit in step S6 and obtaining a fourth asynchronous task execution unit includes the steps of:
[0124] obtaining a second template parameter template<typename Response>;
[0125] installing the second template parameter template<typename Request> on the third asynchronous task execution unit;
[0126] writing a constructor ExecutorSafe on the third asynchronous task execution unit;
[0127] writing the execution logic of the asynchronous task execution unit on the second template parameter template<typename Response>;
[0128] obtaining the fourth asynchronous task execution unit.
[0129] In the embodiment of the present application, when writing an asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit, first, a second template parameter template<typename Response> is obtained, specifically template<typename Response>, a constructor ExecutorSafe is written on the second template parameter template<typename Response>, specifically ExecutorSafe(EventUnit*eu), and then the execution logic of the asynchronous task execution unit, such as VirtualFuture <response>Op(Request request).
[0130] In the embodiment of the present application, the asynchronous task gasket design method based on asynchronous events provided by the present application saves the process of constructing the fourth asynchronous task execution unit by writing the execution logic of the asynchronous task execution unit through the second template parameter template<typename Response> and obtaining the fourth asynchronous task execution unit.
[0131] As Figure 2 In the embodiment of the present application, the asynchronous task gasket design device based on asynchronous events provided by the present application comprises:
[0132] The design module 10 is configured to design a basic execution unit at a program bottom layer.
[0133] The abstract module 20 is configured to perform asynchronous logic abstraction processing on the basic execution unit and obtain a first asynchronous task execution unit.
[0134] The acquisition module 30 is configured to acquire an asynchronous event to be executed at a program upper layer.
[0135] The combination module 40 is configured to combine the asynchronous event into the first asynchronous task execution unit and obtain a second asynchronous task execution unit.
[0136] The first writing module 50 is configured to write a general task asynchronous interface on the second asynchronous task execution unit and obtain a third asynchronous task execution unit.
[0137] The second writing module 60 is configured to write an asynchronous task gasket on the third asynchronous task execution unit and obtain a fourth asynchronous task execution unit.
[0138] In the embodiment of the present application, the asynchronous task gasket design device based on asynchronous events provided by the present application can execute the asynchronous task gasket design method based on asynchronous events provided by the present application.
[0139] Reference will be made to the following description Figure 3 which shows a structural schematic diagram of an electronic device 100 suitable for implementing the embodiments of the present disclosure, and the electronic device 100 can implement the asynchronous task gasket design method based on asynchronous events as described in any of the above embodiments. The electronic device in the embodiments of the present disclosure can include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Personal Computers), PMPs (Portable Multimedia Players), vehicle terminal (for example, vehicle navigation terminal) and the like, and fixed terminals such as digital TVs, desktop computers and the like. Figure 3 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0140] like Figure 3 As shown, the electronic device 100 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 101, which can 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 device 108 into a random access memory (RAM) 103. The RAM 103 also stores various programs and data required for the operation of the electronic device 100. The processing unit 101, ROM 102, and RAM 103 are interconnected via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.
[0141] Typically, the following systems can be connected to I / O interface 105: input devices 106 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 107 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 108 including, for example, magnetic tapes, hard disks, etc.; and communication devices 109. Communication device 109 allows electronic device 100 to communicate wirelessly or wiredly with other devices to exchange data. Although electronic device 100 with various devices is shown in the figure, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0142] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 109, or installed from storage device 108, or installed from ROM 102. When the computer program is executed by processing device 101, it performs the functions defined in the methods of embodiments of this disclosure.
[0143] The following is for reference. Figure 4 It illustrates a schematic diagram of a computer-readable storage medium suitable for implementing embodiments of the present disclosure, the computer-readable storage medium storing a computer program that, when executed by a processor, can implement the asynchronous task pad design method based on asynchronous events as described above.
[0144] 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. The computer-readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, system or device, or any combination of the above. More specific examples of computer-readable storage media can 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution device, system or device. In the present disclosure, the computer-readable signal medium can include a data signal carried in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take many forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate or transmit a program for use by or in conjunction with an instruction execution device, system or device. The program code contained in the computer-readable medium can be transmitted by any suitable medium, including but not limited to a wire, a cable, an RF (radio frequency) or the like, or any suitable combination of the above.
[0145] The computer-readable medium described above can be contained in the electronic device described above; or can exist separately and not be assembled into the electronic device.
[0146] The computer-readable medium described above carries one or more programs, when the one or more programs are executed by the electronic device, the electronic device is caused to: obtain at least two Internet protocol addresses; send a node evaluation request including the at least two Internet protocol addresses to a node evaluation device, wherein the node evaluation device selects an Internet protocol address from the at least two Internet protocol addresses and returns; receive the Internet protocol address returned by the node evaluation device; wherein the obtained Internet protocol address indicates an edge node in a content distribution network.
[0147] Alternatively, the computer readable medium described above carries one or more programs, when the one or more programs are executed by the electronic device, the electronic device is caused to: receive a node evaluation request comprising at least two internet protocol addresses; select an internet protocol address from the at least two internet protocol addresses; and return the selected internet protocol address; wherein the received internet protocol address indicates an edge node in a content distribution network.
[0148] Computer program code for carrying out operations of the present disclosure can be written in any one or more of a variety of programming languages or combinations of languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages such as the "C" programming language or similar programming languages. The program code can 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 latter scenario, the remote computer can 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 can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0149] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of apparatuses, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flow diagrams or block diagrams can represent a module, a procedure, or a part of code, which comprises one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in a different order than that noted in the figures. For example, two blocks noted in succession can in fact be executed substantially concurrently or in the opposite order, depending on the functionality involved. It should also be noted that each block in the block diagrams and / or flow diagrams, and combinations of blocks in the block diagrams and / or flow diagrams, can be implemented by dedicated hardware-based systems that perform the specified functions or operations, or can be implemented by a combination of dedicated hardware-based systems and computer instructions.
[0150] The units described in the embodiments of the present disclosure can be implemented by means of software, or by means of hardware. In some cases, the name of a unit does not constitute a limitation on the unit itself, for example, a first obtaining unit can also be described as "a unit for obtaining at least two internet protocol addresses".
[0151] It should be appreciated that portions of the present disclosure can be implemented in hardware, software, firmware or combinations thereof.
[0152] The application provides an asynchronous event-based asynchronous task shim design method and device, electronic equipment and storage medium. An asynchronous task shim running at a bottom layer is written. The shim is responsible for thread correctness of a program, and a developer does not need to care about execution of a task in which thread, and the developer can randomly deliver the task to different threads, and the bottom layer shim helps to complete thread safety related problems, so that the developer is transparent to the behavior, the burden of the developer is greatly reduced, program correctness is improved, and program robustness is increased.
[0153] Finally, it should also be noted that the terms "comprising", "containing" or any other variant 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 only include those elements, but can also include other elements not expressly listed or inherent to such process, method, article or apparatus. The "first", "second" in the present application can be understood as a noun.
[0154] Although the preferred embodiments of the application have been described, those skilled in the art can make further changes and modifications to the embodiments once they know the basic inventive concept. Therefore, the appended claims are intended to cover all changes and modifications falling within the scope of the application.
[0155] Obviously, those skilled in the art can make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application also intends to include these modifications and variations.< / response> < / typenamerequest> < / response> < / function>
Claims
1. A method for designing an asynchronous task shim based on asynchronous events, the method comprising: The method comprises the steps of: designing an execution unit based on the bottom of a program; performing asynchronous logic abstraction processing on the basic execution unit to obtain a first asynchronous task execution unit; obtaining 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; writing a general task asynchronous interface on the second asynchronous task execution unit to obtain a third asynchronous task execution unit; writing an asynchronous task shim 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 step of performing asynchronous logic abstraction processing on the basic execution unit to obtain a first asynchronous task execution unit comprises the steps of: designing an execution unit class ExecutorUnit 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 obtains all asynchronous execution tasks in an asynchronous execution task queue; the pure virtual interface virtual void add encapsulates all the asynchronous execution tasks; the basic execution unit obtains all the asynchronous execution tasks; the basic execution unit stores all the asynchronous execution tasks to obtain the first asynchronous task execution unit.
2. The asynchronous event-based asynchronous task shim design method of claim 1, wherein, the step of the pure virtual interface virtual void add obtaining all asynchronous execution tasks in an asynchronous execution task queue comprises the steps of: the pure virtual interface virtual void add provides a parameter Function; the parameter Function obtains all parameters and corresponding asynchronous execution tasks in the asynchronous execution task queue; the parameter Function packs all the parameters and corresponding asynchronous execution tasks to obtain a Function object.
3. The asynchronous event-based asynchronous task shim design method of claim 2, wherein, before the step of the pure virtual interface virtual void add providing the parameter Function, the method further comprises the steps of: presetting an empty queue queueUnit; obtaining the asynchronous execution tasks; storing all the asynchronous execution tasks in the empty queue queueUnit in a preset order to obtain the asynchronous execution task queue.
4. The asynchronous event-based asynchronous task shim design method of claim 1, wherein, the step of combining the asynchronous event into the first asynchronous task execution unit to obtain 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; obtaining a thread on which the first asynchronous task execution unit runs; determining whether a pointer fn of the event thread running interface void runInEventThread is empty; if yes, not executing the asynchronous event; if no, determining whether the asynchronous event is being executed in the thread; if yes, executing the asynchronous event; If not, the asynchronous event is added to the first asynchronous task execution unit and a second asynchronous task execution unit is obtained.
5. The asynchronous event-based asynchronous task shim design method of claim 1, wherein, The step of writing a general task asynchronous interface on the second asynchronous task execution unit and obtaining a third asynchronous task execution unit comprises: obtaining a first template parameter template<typename Request>; installing the first template parameter template<typename Request> on the second asynchronous task execution unit; writing a pure virtual function interface Virtual Future on the second asynchronous task execution unit; obtaining an asynchronous execution task and its corresponding parameters through the pure virtual function interface Virtual Future; encapsulating the asynchronous execution task and its corresponding parameters using the first template parameter template<typename Request>; obtaining the third asynchronous task execution unit.
6. The asynchronous event-based asynchronous task shim design method of claim 1, wherein, The step of writing an asynchronous task shim on the third asynchronous task execution unit and obtaining a fourth asynchronous task execution unit comprises: obtaining a second template parameter template<typename Response>; installing the second template parameter template<typename Request> on the third asynchronous task execution unit; writing a constructor function ExecutorSafe on the third asynchronous task execution unit; writing an execution logic of the asynchronous task execution unit on the second template parameter template<typename Response>; obtaining the fourth asynchronous task execution unit.
7. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected in communication with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the asynchronous task shim design method based on asynchronous events according to any one of claims 1-6.
8. A storage medium storing a computer program, characterized by The computer program enables the asynchronous task shim design method based on asynchronous events according to any one of claims 1-6 to be implemented when executed by a processor.
Citation Information
Patent Citations
Data asynchronous processing method and device based on synchronous programming
CN109002286A
Task execution method and device
CN110688203A