A thread creation method, system, device and computer storage medium
By receiving the type identifier in the thread creation method and creating the target thread based on it, the problem of insufficient thread types in the existing technology is solved, and more flexible thread creation is achieved, improving the user experience.
Patent Information
- Application Number
- CN202011634956.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2040-12-31
AI Technical Summary
The existing technology fails to consider the different types of threads when creating threads, resulting in the created default threads that cannot meet the needs of users and affect the user experience.
By receiving thread creation instructions, we judge whether the target thread exists, and determine the thread type based on the type identification carried, and create the target thread based on this type. Supports multiple thread types, such as NPL type, NPL_LITE type, DLL type, and NPL_ExternalLuaState type.
This allows users to specify the type of threads to be created through specific thread identification, which meets the needs of different users and improves the user experience.
Smart Images

Figure CN112631760B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a thread creation method, system, device and computer storage medium. Background Art
[0002] In common operating systems, processes and threads are generally created and managed in a specific way to manage multitasking. When creating a thread, it is generally necessary to obtain the process identifier, thread identifier, process number, and thread number, and then create the thread through functions such as pthread_create().
[0003] However, in the prior art, different types of threads are not taken into consideration when creating a thread. Generally, a default thread is created, but the default thread may not meet the needs of the user. The user needs to associate the content to be executed by the thread by himself, which affects the user experience. Summary of the invention
[0004] In order to solve the problems of the prior art, the present application provides a thread creation method, system, device and computer storage medium, which are used to allow users to specify the type of thread to be created through a specific thread identifier to meet the needs of different users.
[0005] The first aspect of the present application provides a thread creation method, the method comprising:
[0006] Receiving a thread creation instruction, wherein the thread creation instruction is used to request creation of a target thread;
[0007] Determine whether the target thread exists;
[0008] If it is determined that the target thread does not exist, determining whether the thread creation instruction carries a type identifier;
[0009] If it is determined that the thread creation instruction carries a type identifier, determining the thread type of the target thread according to the type identifier;
[0010] The target thread is created based on the thread type.
[0011] Optionally, the thread types include: NPL type, NPL_LITE type, DLL type and NPL_ExternalLuaState type.
[0012] Optionally, if the thread type is an NPL type, creating the target thread based on the thread type includes:
[0013] Creating the target thread by loading the NPL function and the ParaEngine function in a running environment embedded with Lua;
[0014] If the thread type is NPL_LITE type, then creating the target thread based on the thread type includes:
[0015] Creating the target thread by loading the NPL function in a running environment embedded with Lua;
[0016] If the thread type is a DLL type, then creating the target thread based on the thread type includes:
[0017] Create the target thread by loading a blank function;
[0018] If the thread type is NPL_ExternalLuaState type, then creating the target thread based on the thread type includes:
[0019] The target thread is created by loading the NPL function and the ParaEngine function in a running environment without embedded Lua.
[0020] Optionally, determining whether the target thread exists includes:
[0021] Determine the thread name carried in the thread creation instruction;
[0022] It is determined whether the target thread exists according to the thread name.
[0023] Optionally, the method further includes:
[0024] If it is determined that the thread creation instruction does not carry a type identifier, determining that the thread type of the target thread is a default type;
[0025] The target thread is created based on the default type.
[0026] Optionally, the default type is NPL type;
[0027] The creating the target thread based on the default type comprises:
[0028] The target thread is created by loading the NPL function and the ParaEngine function in the running environment embedded with Lua.
[0029] Optionally, after creating the target thread based on the thread type, the method further includes:
[0030] Adding the target thread to the thread pool;
[0031] Return to the target thread.
[0032] A second aspect of the present application provides a thread creation system, the system comprising:
[0033] A receiving unit, used for receiving a thread creation instruction, wherein the thread creation instruction is used for requesting to create a target thread;
[0034] A first determination unit, used to determine whether the target thread exists;
[0035] a second determination unit, configured to determine whether the thread creation instruction carries a type identifier when the first determination unit determines that the target thread does not exist;
[0036] a first determining unit, configured to determine the thread type of the target thread according to the type identifier when the second determining unit determines that the thread creation instruction carries a type identifier;
[0037] The first creating unit is used to create the target thread based on the thread type.
[0038] Optionally, the thread types include: NPL type, NPL_LITE type, DLL type and NPL_ExternalLuaState type.
[0039] Optionally, if the thread type is an NPL type, the first creation unit is specifically used to:
[0040] Creating the target thread by loading the NPL function and the ParaEngine function in a running environment embedded with Lua;
[0041] If the thread type is NPL_LITE type, the first creation unit is specifically used for:
[0042] Creating the target thread by loading the NPL function in a running environment embedded with Lua;
[0043] If the thread type is a DLL type, the first creation unit is specifically used for:
[0044] Create the target thread by loading a blank function;
[0045] If the thread type is NPL_ExternalLuaState type, the first creation unit is specifically used for:
[0046] The target thread is created by loading the NPL function and the ParaEngine function in a running environment without embedded Lua.
[0047] Optionally, the first judging unit includes:
[0048] A determination module, used to determine the thread name carried in the thread creation instruction;
[0049] The judging module is used to judge whether the target thread exists according to the thread name.
[0050] Optionally, the system further includes:
[0051] A second determining unit, configured to determine that the thread type of the target thread is a default type when the second determining unit determines that the thread creation instruction does not carry a type identifier;
[0052] The second creating unit is used to create the target thread based on the default type.
[0053] Optionally, the default type is NPL type;
[0054] The second creation unit is specifically used for:
[0055] The target thread is created by loading the NPL function and the ParaEngine function in the running environment embedded with Lua.
[0056] Optionally, the system further includes:
[0057] An adding unit, used for adding the target thread to the thread pool;
[0058] A return unit is used to return to the target thread.
[0059] A third aspect of the present application provides a thread creation device, the device comprising:
[0060] Processor, memory, input-output unit, and bus;
[0061] The processor is connected to the memory, the input and output unit, and the bus;
[0062] The memory stores a program, and the processor calls the program to execute the first aspect and any optional thread creation method in the first aspect.
[0063] A fourth aspect of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the program executes the first aspect and any optional thread creation method in the first aspect.
[0064] It can be seen from the above technical solutions that this application has the following advantages:
[0065] By defining multiple different types of threads in the NPL language, each type of thread is pre-associated with the corresponding thread content to be executed, so that when a user creates a new thread in the NPL runtime environment, he can specify the type of thread to be created through a specific thread identifier to meet the needs of different users and improve the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the technical solution in the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0067] Figure 1 A schematic diagram of an embodiment of a thread creation method provided in this application;
[0068] Figure 2 A flowchart of another embodiment of the thread creation method provided by the present application;
[0069] Figure 3 A schematic diagram of the structure of an embodiment of a thread creation system provided by the present application;
[0070] Figure 4 A schematic diagram of another embodiment of the thread creation system provided by the present application;
[0071] Figure 5 This is a schematic diagram of the structure of an embodiment of a thread creation device provided in this application. DETAILED DESCRIPTION
[0072] The present application provides a thread creation method, system, device and computer storage medium, which are used to enable a user to specify the type of thread to be created through a specific thread identifier to meet the needs of different users.
[0073] It should be noted that the thread creation method provided in this application can be applied to a terminal, a system, or a server. For example, the terminal can be a smart phone or a computer, a tablet computer, a smart TV, a smart watch, a portable computer terminal, or a fixed terminal such as a desktop computer. For the convenience of explanation, this application uses the terminal as an example for explanation.
[0074] See also Figure 1 , Figure 1 An embodiment of a thread creation method provided by the present application includes:
[0075] 101. Receive a thread creation instruction, where the thread creation instruction is used to request creation of a target thread;
[0076] After receiving the thread creation instruction, the terminal enters the thread creation process, executes the thread creation method through subsequent steps, and obtains the target thread. The target thread is the new thread created by the user. It should be noted that the thread creation instruction can be initiated by the user or automatically created when the program itself starts, which is not limited here.
[0077] 102. Determine whether the target thread exists, if not, execute step 103;
[0078] Since the target thread may have been created, creating another target thread at this time will result in two identical threads appearing at the same time. Therefore, after receiving the thread creation instruction, the terminal needs to determine whether the target thread exists. When the terminal determines that the target thread does not exist, step 103 is executed.
[0079] 103. If it is determined that the target thread does not exist, determine whether the thread creation instruction carries a type identifier, and if so, execute step 104;
[0080] In this embodiment, threads are divided into multiple different types, and type identifiers are used to distinguish threads of different types.
[0081] When the terminal determines that the target thread does not exist, it determines whether the thread creation instruction carries a type identifier, so that the thread type of the target thread can be determined through the type identifier.
[0082] 104. If it is determined that the thread creation instruction carries a type identifier, determine the thread type of the target thread according to the type identifier;
[0083] In this embodiment, the type identifier can be used to determine the type of the thread, so the terminal can determine the thread type of the target thread according to the type identifier to create a target thread corresponding to the type identifier.
[0084] 105. Create the target thread based on the thread type.
[0085] After determining the type identifier carried in the thread creation instruction, the terminal can determine the thread type of the target thread according to the type identifier, thereby creating a target thread of the specified type.
[0086] In this embodiment, a plurality of different types of threads are defined, wherein each type of thread is pre-associated with the corresponding thread content to be executed, so that when a user creates a new thread, the user can specify the type of thread to be created through a specific thread identifier, thereby meeting the needs of different users and improving the user experience.
[0087] In another embodiment, the application of the thread creation method provided by the present application in the NPL operating environment is introduced. NPL is a general open source language. In the NPL operating environment, threads can be divided into four types: NPL type, NPL_LITE type, DLL type, and NPL_ExternalLuaState type. Each type of thread is pre-associated with the thread content to be executed to cope with different application scenarios. The following is a detailed introduction:
[0088] 1.NPL Type:
[0089] The NPL type embeds the Lua runtime environment. When a thread of the NPL type is created, all NPL functions and ParaEngine functions are loaded.
[0090] 2.NPL_LITE type:
[0091] The NPL_LITE type also embeds the Lua runtime environment and is a simplified version of the NPL type thread. When creating a NPL_LITE type thread, only NPL functions and some limited functions will be loaded.
[0092] 3.DLL type:
[0093] When creating a DLL type thread, no function will be loaded. This type of thread is usually used with a dynamic link library plug-in.
[0094] 4.NPL_ExternalLuaState type:
[0095] When creating a thread of type NPL_ExternalLuaState, all NPL functions and ParaEngine functions will be loaded. Unlike the NPL type, this type does not embed the Lua runtime environment and needs to be set externally.
[0096] Based on the above introduction, please refer to Figure 2 , Figure 2 Another embodiment of the thread creation method provided by the present application includes:
[0097] 201. Receive a thread creation instruction, where the thread creation instruction is used to request creation of a target thread;
[0098] Step 201 in this embodiment is similar to step 101 in the above embodiment and will not be described again here.
[0099] 202. Determine the thread name carried in the thread creation instruction;
[0100] In the NPL environment, the name of the NPL thread serves to identify the thread. Each NPL thread has an independent name. Therefore, after receiving a thread creation instruction, the terminal can determine whether there are other threads with the same name as the target thread by determining the thread name carried in the thread creation instruction, thereby determining whether the target thread has been created.
[0101] 203. Determine whether the target thread exists according to the thread name, if not, execute step 204, if yes, execute step 210;
[0102] Specifically, if there are other threads with the same name as the target thread, it is determined that the target thread exists, and step 210 is executed at this time; if there are no other threads with the same name as the target thread, it is determined that the target thread does not exist, and step 204 is executed at this time to execute the thread creation method through subsequent steps to obtain the target thread.
[0103] 204. Determine whether the thread creation instruction carries a type identifier. If yes, execute step 205; otherwise, execute step 207.
[0104] In this embodiment, threads are divided into multiple different types, and type identifiers are used to distinguish threads of different types.
[0105] When the terminal determines that the target thread does not exist, it determines whether the thread creation instruction carries a type identifier, thereby determining the specific thread type of the target thread through the type identifier.
[0106] 205. Determine the thread type of the target thread according to the type identifier;
[0107] In this embodiment, the NPL.CreateRuntimeState(name,type) function can be used to create a thread. When creating a thread, the thread name name and the thread type type need to be specified, where the thread type type can be represented by numbers, that is, numbers from 0 to 3 are used to represent NPL type, NPL_LITE type, DLL type and NPL_ExternalLuaState type respectively.
[0108] The terminal first determines the type identifier carried in the thread creation instruction, and then determines the thread type of the target thread according to the type identifier. For example, NPL.CreateRuntimeState("A", 0) indicates the creation of NPL type thread A. NPL.CreateRuntimeState("B", 2) indicates the creation of DLL type thread B.
[0109] 206. Create the target thread based on the thread type;
[0110] After determining the thread type of the target thread, the terminal creates a target thread of this type.
[0111] In this embodiment, threads are divided into four types: NPL type, NPL_LITE type, DLL type and NPL_ExternalLuaState type. Specifically:
[0112] When the thread type of the target thread is NPL type, the target thread is created by loading NPL function and ParaEngine function in the runtime environment embedded with Lua;
[0113] When the thread type of the target thread is NPL_LITE, the target thread is created by loading the NPL function in the runtime environment embedded with Lua;
[0114] When the thread type of the target thread is a DLL type, the target thread is created by loading a blank function;
[0115] When the thread type of the target thread is NPL_ExternalLuaState type, the target thread is created by loading NPL functions and ParaEngine functions in a running environment without embedded Lua.
[0116] 207. Determine that the thread type of the target thread is a default type;
[0117] If the terminal determines that the thread creation instruction does not carry a type identifier, it determines that the target thread is a default type of thread, where the default type can be any one of the four NPL thread types, which is not specifically limited here.
[0118] 208. Create the target thread based on the default type;
[0119] When the terminal determines that the user has not specified the type of the thread to be created, the terminal creates the thread based on the default type.
[0120] In some embodiments, the default type is pre-set to the NPL type. When the user does not specify the type of thread to be created, the terminal creates an NPL type thread, that is, creates the target thread by loading the NPL function and the ParaEngine function in the operating environment embedded with Lua.
[0121] 209. Add the target thread to the thread pool;
[0122] After each NPL engine is started, it will maintain a thread pool, which consists of already created threads. After the terminal creates a target thread of a specified type, it automatically adds the target thread to the thread pool.
[0123] 210. Return to the target thread.
[0124] The terminal returns to the target thread to execute the task of the target thread.
[0125] In this embodiment, four different types of threads are defined, each type of thread is pre-associated with the corresponding thread content to be executed, and each type of thread corresponds to a different operating environment. Therefore, when creating a new thread, the user can specify the type of thread to be created through a specific thread identifier, so as to meet the needs of different users and improve the user experience.
[0126] See also Figure 3 , Figure 3 An embodiment of a thread creation system provided by the present application includes:
[0127] A receiving unit 301 is used to receive a thread creation instruction, where the thread creation instruction is used to request the creation of a target thread;
[0128] A first determination unit 302 is used to determine whether the target thread exists;
[0129] A second determination unit 303 is configured to determine whether the thread creation instruction carries a type identifier when the first determination unit determines that the target thread does not exist;
[0130] A first determining unit 304 is configured to determine the thread type of the target thread according to the type identifier when the second determining unit determines that the thread creation instruction carries a type identifier;
[0131] The first creating unit 305 is configured to create the target thread based on the thread type.
[0132] In this embodiment, a plurality of different types of threads are defined, wherein each type of thread is pre-associated with the corresponding thread content to be executed, so that after the receiving unit 301 receives the thread creation instruction, the first determination unit 304 can specify the type of thread to be created through a specific thread identifier, and the first creation unit 305 creates a thread of the corresponding type based on the specific type to meet the needs of different users and improve the user experience.
[0133] The thread creation system provided by this application is described in detail below. Figure 4 , Figure 4 Another embodiment of the thread creation system provided by the present application includes:
[0134] A receiving unit 401 is used to receive a thread creation instruction, where the thread creation instruction is used to request the creation of a target thread;
[0135] A first determination unit 402 is used to determine whether the target thread exists;
[0136] A second determination unit 403 is configured to determine whether the thread creation instruction carries a type identifier when the first determination unit determines that the target thread does not exist;
[0137] A first determining unit 404 is configured to determine the thread type of the target thread according to the type identifier when the second determining unit determines that the thread creation instruction carries a type identifier;
[0138] The first creating unit 405 is configured to create the target thread based on the thread type.
[0139] In this embodiment, the first determination unit 402 includes:
[0140] A determination module 4021 is used to determine the thread name carried in the thread creation instruction;
[0141] The determination module 4022 is used to determine whether the target thread exists according to the thread name.
[0142] In this embodiment, the system further includes:
[0143] A second determining unit 406, configured to determine that the thread type of the target thread is a default type when the second determining unit determines that the thread creation instruction does not carry a type identifier;
[0144] A second creation unit 407, configured to create the target thread based on the default type;
[0145] An adding unit 408 is used to add the target thread to the thread pool;
[0146] The returning unit 409 is used to return to the target thread.
[0147] In this embodiment, the functions of each unit and module are the same as those described above. Figure 2 The steps in the method embodiment shown correspond to each other and will not be repeated here.
[0148] This application also provides a thread creation device, see Figure 5 , Figure 5 An embodiment of a thread creation device provided by the present application includes:
[0149] Processor 501, memory 502, input and output unit 503, bus 504;
[0150] The processor 501 is connected to the memory 502, the input and output unit 503 and the bus 504;
[0151] The memory 502 stores a program, and the processor 501 calls the program to execute any of the above thread creation methods.
[0152] The present application also relates to a computer-readable storage medium on which a program is stored, wherein when the program is run on a computer, the computer is caused to execute any of the above thread creation methods.
[0153] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0154] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0155] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0156] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0157] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A thread creation method, characterized in that: The method comprises: Receiving a thread creation instruction initiated by a user, wherein the thread creation instruction is used to request creation of a target thread; Determine whether the target thread exists; If it is determined that the target thread does not exist, determining whether the thread creation instruction carries a type identifier; If it is determined that the thread creation instruction carries a type identifier, determining the thread type of the target thread according to the type identifier; Creating the target thread based on the thread type; After determining whether the thread creation instruction carries a type identifier, the method further includes: If it is determined that the thread creation instruction does not carry a type identifier, determining that the thread type of the target thread is a default type; Creating the target thread based on the default type; The default type is NPL type; The creating the target thread based on the default type comprises: The target thread is created by loading the NPL function and the ParaEngine function in the running environment embedded with Lua.
2. The thread creation method according to claim 1, characterized in that: The thread types include: NPL type, NPL_LITE type, DLL type and NPL_ExternalLuaState type.
3. The thread creation method according to claim 2, characterized in that: If the thread type is an NPL type, then creating the target thread based on the thread type includes: Creating the target thread by loading the NPL function and the ParaEngine function in a running environment embedded with Lua; If the thread type is NPL_LITE type, then creating the target thread based on the thread type includes: Creating the target thread by loading the NPL function in a running environment embedded with Lua; If the thread type is a DLL type, then creating the target thread based on the thread type includes: Create the target thread by loading a blank function; If the thread type is NPL_ExternalLuaState type, then creating the target thread based on the thread type includes: The target thread is created by loading the NPL function and the ParaEngine function in a running environment without embedded Lua.
4. The thread creation method according to claim 1, characterized in that: Determining whether the target thread exists includes: Determine the thread name carried in the thread creation instruction; It is determined whether the target thread exists according to the thread name.
5. The thread creation method according to any one of claims 1 to 4, characterized in that: After creating the target thread based on the thread type, the method further includes: Adding the target thread to the thread pool; Return to the target thread.
6. A thread creation system, characterized in that: The system comprises: A receiving unit, configured to receive a thread creation instruction initiated by a user, wherein the thread creation instruction is used to request the creation of a target thread; A first determination unit, used to determine whether the target thread exists; a second determination unit, configured to determine whether the thread creation instruction carries a type identifier when the first determination unit determines that the target thread does not exist; a first determining unit, configured to determine the thread type of the target thread according to the type identifier when the second determining unit determines that the thread creation instruction carries a type identifier; A first creating unit, configured to create the target thread based on the thread type; The system further comprises: A second determining unit, configured to determine that the thread type of the target thread is a default type when the second determining unit determines that the thread creation instruction does not carry a type identifier; The second creating unit is used to create the target thread based on the default type.
7. A thread creation device, characterized in that: The device comprises: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a program stored thereon, wherein the program, when executed on a computer, performs the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Thread establishing and processing method and apparatus
CN105302557A
User-level thread control system and method thereof
CN110928696A