A pointer variable release method and device

By recording and managing the mapping relationship between pointer variables and reading threads, the problem of business interruption caused by writing thread exceptions is solved, and the functions of concurrent access and delayed release of pointer variables by multiple reading threads are realized, avoiding the need for additional lock protection.

CN113656111BActive Publication Date: 2025-01-21NEW H3C SECURITY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111039845.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-06
Publication Date
2025-01-21
Estimated Expiration
2041-09-06

AI Technical Summary

Technical Problem

When multiple threads access pointer variables concurrently, the write thread exception causes the lock to be released, causing other threads to be unable to access data, resulting in business interruption.

Method used

By recording the mapping relationship between the pointer variable and the reading thread, when the reading thread is closed, the mapping relationship is deleted and the pointer variable is released to avoid affecting the reading thread access when the writing thread is busy or abnormal.

Benefits of technology

When the writing thread needs to release the pointer variable, delayed release is implemented to support concurrent access by multiple reading threads, avoid business interruption, and reduce the need for additional lock protection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113656111B_ABST
    Figure CN113656111B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a pointer variable release method and device, which relates to the field of computer technology. The method includes: when a write thread needs to release a first pointer variable and there is currently an open read thread, the mapping relationship between the first pointer variable and the currently opened read thread is recorded, and the first pointer variable is determined as a pointer variable to be released; when the opened first read thread is closed, the second pointer variable corresponding to the first read thread in the current pointer variable to be released is determined; the mapping relationship between the second pointer variable and the first read thread is deleted; if there is no corresponding read thread for the second pointer variable in the currently recorded mapping relationship, the second pointer variable is released. In this way, business interruption can be avoided when multiple read threads concurrently access the pointer variable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a pointer variable releasing method and device. Background Art

[0002] During the running of an application, data can be accessed through multiple threads. For example, in an application based on the C language, data can be written to a pointer variable through a write thread, and data can also be read from the pointer variable through a read thread.

[0003] In the related art, concurrent access of threads is implemented based on locks. For example, before a thread performs read or write access, it needs to acquire a lock first. After successfully acquiring the lock, the thread can access the corresponding data. After successfully acquiring the lock, if the thread is abnormal and cannot release the lock, other threads will not be able to access the data because they cannot acquire the lock, which will also cause business interruption. Summary of the invention

[0004] The purpose of the embodiment of the present application is to provide a pointer variable release method and device, which can avoid service interruption when multiple read threads concurrently access the pointer variable. The specific technical solution is as follows:

[0005] In a first aspect, in order to achieve the above-mentioned purpose, an embodiment of the present application discloses a pointer variable release method, the method comprising:

[0006] When the write thread needs to release the first pointer variable and there is currently an opened read thread, a mapping relationship between the first pointer variable and the currently opened read thread is recorded, and the first pointer variable is determined as a pointer variable to be released;

[0007] When the opened first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the pointer variables currently to be released;

[0008] Deleting the mapping relationship between the second pointer variable and the first reading thread;

[0009] If there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, the second pointer variable is released.

[0010] Optionally, the method further includes:

[0011] When the write thread needs to release the first pointer variable and there is no currently opened read thread, the first pointer variable is released.

[0012] Optionally, recording a mapping relationship between the first pointer variable and the currently opened read thread includes:

[0013] The identifier of the currently opened read thread is recorded in the memory space corresponding to the first pointer variable.

[0014] Optionally, before recording the mapping relationship between the first pointer variable and the currently opened read thread and determining the first pointer variable as the pointer variable to be released, the method further includes:

[0015] Determine whether there is a bit with a specified value in a preset global variable; wherein the preset global variable includes multiple bits, each bit corresponding to a read thread;

[0016] If a bit with a specified value exists in the preset global variable, it is determined that a currently opened read thread already exists;

[0017] If the bit with the specified value does not exist in the preset global variable, it is determined that there is no currently opened read thread.

[0018] Optionally, the method further includes:

[0019] When the second reading thread is started, the bit corresponding to the second reading thread in the preset global variable is modified to a specified value.

[0020] Optionally, the method further includes:

[0021] When the opened first reading thread is closed, the bit corresponding to the first reading thread in the preset global variable is deleted.

[0022] In a second aspect, in order to achieve the above-mentioned purpose, an embodiment of the present application discloses a pointer variable release device, the device comprising:

[0023] A to-be-released pointer variable determination module, configured to, when a write thread needs to release a first pointer variable and a currently opened read thread already exists, record a mapping relationship between the first pointer variable and the currently opened read thread, and determine the first pointer variable as a to-be-released pointer variable;

[0024] A second pointer variable determining module, configured to determine, when closing the opened first reading thread, a second pointer variable corresponding to the first reading thread in the current pointer variables to be released;

[0025] A deleting module, used for deleting the mapping relationship between the second pointer variable and the first reading thread;

[0026] The first releasing module is used to release the second pointer variable if there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship.

[0027] Optionally, the device further comprises:

[0028] The second releasing module is used to release the first pointer variable when the writing thread needs to release the first pointer variable and there is no currently opened reading thread.

[0029] Optionally, the module for determining the pointer variable to be released includes:

[0030] The recording submodule is used to record the identifier of the currently opened reading thread in the memory space corresponding to the first pointer variable.

[0031] Optionally, the device further comprises:

[0032] A judgment module, configured to judge whether there is a bit with a specified value in a preset global variable before recording the mapping relationship between the first pointer variable and the currently opened read thread and determining the first pointer variable as the pointer variable to be released; wherein the preset global variable includes a plurality of bits, each bit corresponding to a read thread;

[0033] A first processing module, configured to determine that a currently opened read thread exists if a bit with a specified value exists in the preset global variable;

[0034] The second processing module is used to determine that there is no currently opened reading thread if there is no bit with a specified value in the preset global variable.

[0035] Optionally, the device further comprises:

[0036] The modification module is used to modify the bit corresponding to the second reading thread in the preset global variable to a specified value when the second reading thread is started.

[0037] Optionally, the device further comprises:

[0038] The deleting module is used to delete the bit corresponding to the first reading thread in the preset global variable when the opened first reading thread is closed.

[0039] In another aspect of the implementation of the present application, in order to achieve the above-mentioned purpose, the embodiment of the present application further discloses an electronic device, the electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;

[0040] The memory is used to store computer programs;

[0041] The processor is used to implement the pointer variable release method described in the first aspect when executing the program stored in the memory.

[0042] In another aspect of the implementation of the present application, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the pointer variable release method described in the first aspect above is implemented.

[0043] In another aspect of the implementation of the present application, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the pointer variable releasing method described in the first aspect above.

[0044] Beneficial effects of the embodiments of the present application:

[0045] The pointer variable releasing method provided in the embodiment of the present application records the mapping relationship between the first pointer variable and the currently opened reading thread when the writing thread needs to release the first pointer variable and there is currently an opened reading thread, and determines the first pointer variable as the pointer variable to be released; when the opened first reading thread is closed, determines the second pointer variable corresponding to the first reading thread in the current pointer variables to be released; deletes the mapping relationship between the second pointer variable and the first reading thread; if there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, releases the second pointer variable.

[0046] Based on the above processing, for the pointer variable that needs to be released by the write thread, if there is currently an open read thread, the release of the pointer variable can be delayed, and the read thread corresponding to the pointer variable can be recorded, that is, the read thread that may access the pointer variable is recorded. Furthermore, when the read threads corresponding to the pointer variable are all closed, the pointer variable is released, and multiple read threads can access the pointer variable concurrently. In addition, since there is no need for additional locking to protect the pointer variable, even if the write thread is busy or hung due to a fault, it will not affect the read thread's access to data, and business interruption can be avoided.

[0047] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0049] Figure 1 A flowchart of a pointer variable release method provided in an embodiment of the present application;

[0050] Figure 2A flowchart of another pointer variable release method provided in an embodiment of the present application;

[0051] Figure 3 A structural diagram of a pointer variable releasing device provided in an embodiment of the present application;

[0052] Figure 4 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.

[0054] The embodiment of the present application provides a pointer variable release method, which can be applied to an electronic device that can run an application based on C language. In the process of running the application, the electronic device can access the data stored in the memory space indicated by the pointer variable through a thread. Accordingly, at the end of the access, the delayed release of the pointer variable can be realized according to the demand, that is, the memory space corresponding to the pointer variable is released.

[0055] See also Figure 1 , Figure 1 A flowchart of a pointer variable release method provided in an embodiment of the present application, the method may include the following steps:

[0056] S101: When a write thread needs to release a first pointer variable and there is currently an enabled read thread, a mapping relationship between the first pointer variable and the currently enabled read thread is recorded, and the first pointer variable is determined as a pointer variable to be released.

[0057] S102: When the opened first reading thread is closed, a second pointer variable corresponding to the first reading thread in the pointer variables currently to be released is determined.

[0058] S103: Delete the mapping relationship between the second pointer variable and the first reading thread.

[0059] S104: If there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, the second pointer variable is released.

[0060] The pointer variable release method provided in the embodiment of the present application can delay the release of the pointer variable that needs to be released by the write thread when there is currently an open read thread, and can record the read thread corresponding to the pointer variable, that is, record the read thread that may access the pointer variable. Furthermore, when the read threads corresponding to the pointer variable are all closed, the pointer variable is released, and multiple read threads can access the pointer variable concurrently. It can effectively support the scenario of one write thread and multiple read threads concurrently. In addition, since there is no need for additional locking to protect the pointer variable, even if the write thread is busy or hung due to a fault, it will not affect the read thread's access to data, which can avoid business interruption and is beneficial to operation and maintenance management and fault location.

[0061] For step S101, the write thread needs to release the first pointer variable. For example, if a network change causes the need to delete a routing table entry, the pointer variable corresponding to the routing table entry needs to be released. In one implementation, the write thread can release the first pointer variable by calling a release function. In addition, before releasing the first pointer variable, the access entry of the first pointer variable needs to be closed so that the subsequently opened read thread cannot access the first pointer variable.

[0062] At this time, the electronic device can determine whether there is an open read thread currently. If there is an open read thread, the opened read thread may read the data in the memory space pointed to by the first pointer variable, so the first pointer variable is not released currently.

[0063] The electronic device may record the mapping relationship between the first pointer variable and the currently opened read thread, that is, the electronic device may record the read thread that may currently access the first pointer variable.

[0064] In one embodiment, the electronic device may add the first pointer variable to a preset linked list (which may be referred to as a linked list of pointer variables to be released) to determine the first pointer variable as a pointer variable to be released.

[0065] With respect to step S102, the first reading thread has completed access to the pointer variable, and at this time, the first reading thread can be closed. In one implementation, when the first reading thread is turned on, a registration function can be called by the first reading thread to register, and then the pointer variable can be accessed. Correspondingly, when the first reading thread completes access to the pointer variable, a deregistration function is called by the first reading thread to deregister. At this time, the electronic device can close the first reading thread.

[0066] Then, the electronic device can query the current pointer variable to be released to determine whether there is a pointer variable (ie, a second pointer variable) corresponding to the first reading thread. The determined second pointer variable can be one or more.

[0067] If the second pointer variable exists, since the first reading thread is closed at this time, step S103 can be executed to delete the mapping relationship between the second pointer variable and the first reading thread, that is, to determine that the second pointer variable no longer corresponds to the first reading thread. In other words, the first reading thread does not exist in the reading thread currently accessing the second pointer variable.

[0068] For step S104, for each second pointer variable, the reading thread corresponding to the second pointer variable in the recorded mapping relationship indicates the reading thread that may currently access the second pointer variable. Therefore, after deleting the mapping relationship between the second pointer variable and the first reading thread, if there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, it indicates that there is no reading thread currently accessing the second pointer variable, and then, the second pointer variable can be released, that is, the memory space pointed to by the second pointer variable is released.

[0069] In one embodiment, the method may further include the following steps:

[0070] When the write thread needs to release the first pointer variable and there is no currently opened read thread, the first pointer variable is released.

[0071] In an embodiment of the present application, when the write thread needs to release the first pointer variable, if there is no currently opened read thread, it indicates that there is currently no read thread accessing the first pointer variable. Then, the first pointer variable can be directly released, that is, the memory space pointed to by the first pointer variable is released.

[0072] In one embodiment, before the above step S101, the method may further include the following steps:

[0073] Step 1: Determine whether there is a bit with a specified value in the preset global variable.

[0074] Step 2: If a bit with a specified value exists in the preset global variable, it is determined that there is currently an open read thread.

[0075] Step 3: If the bit with the specified value does not exist in the preset global variable, it is determined that there is no currently opened reading thread.

[0076] The preset global variable includes multiple bits, each bit corresponds to a read thread. A bit is a specified value, indicating that the read thread corresponding to the bit is enabled.

[0077] In the embodiment of the present application, a global variable may be pre-set, and the global variable may include multiple bits. In one implementation, the global variable may be represented by a global data structure, for example, a global BitMap (bitmap, which may be called the first bitmap).

[0078] In one implementation, if there is no currently opened read thread, the first bitmap can be 0; if a new read thread is opened, a handle 0 can be assigned to the read thread, indicating the bit number of the corresponding bit in the first bitmap, and the first bitmap can be modified to 0x1, that is, the bit numbered 0 in the first bitmap is modified to 1; similarly, if another new read thread is opened, a handle 1 can be assigned to the new read thread, indicating the bit number of the corresponding bit in the first bitmap, and the first bitmap can be modified to 0x11, that is, the bit numbered 1 in the first bitmap is modified to 1.

[0079] In the above example, the specified value is 1, that is, if there is a bit of 1 in the preset global variable, it indicates that there is currently an open read thread, and the bit number of the bit where 1 is located is the handle of the opened read thread.

[0080] In one embodiment, see Figure 2 ,exist Figure 1 On the basis of, the above step S101 may include:

[0081] S1011: When the write thread needs to release the first pointer variable and there is currently an open read thread, the identifier of the currently opened read thread is recorded in the memory space corresponding to the first pointer variable, and the first pointer variable is determined as a pointer variable to be released.

[0082] In the embodiment of the present application, the electronic device can allocate memory space for the pointer variable through a memory allocation function. Accordingly, in addition to storing the data represented by the first pointer variable, the allocated memory space can also allocate an additional header for recording the identifier of the read thread corresponding to the first pointer variable. The identifier of the read thread can be represented by its handle.

[0083] In one implementation, the header may record a data structure corresponding to the first pointer variable, for example, a BitMap, which may be called a second bitmap. Based on the second bitmap, the identifier of the read thread corresponding to the first pointer variable may be recorded.

[0084] For example, the electronic device can query the above-mentioned first bitmap and record the value of the above-mentioned first bitmap in the second bitmap corresponding to the first pointer variable. Accordingly, each bit in the second bitmap represents a read thread corresponding to the first pointer variable, and the bit number of each bit is the handle of the corresponding read thread.

[0085] In one embodiment, the method may further include the following steps:

[0086] When the second reading thread is started, the bit corresponding to the second reading thread in the preset global variable is modified to a specified value.

[0087] In an embodiment of the present application, if a new read thread (i.e., a second read thread) is started, the bit corresponding to the second read thread in the preset global variable can be modified to a specified value. For example, the handle of the second read thread can be determined, and the bit corresponding to the handle in the preset global variable can be modified to a specified value. Furthermore, through the above-mentioned preset global variable, it can be determined that the second read thread is currently started, and the identifier of the second read thread can be recorded in the memory space corresponding to the second pointer variable to indicate that the second read thread may access the pointer variable.

[0088] In one embodiment, the method may further include the following steps:

[0089] When the opened first reading thread is closed, the bit corresponding to the first reading thread in the preset global variable is deleted.

[0090] In an embodiment of the present application, when the first reading thread is closed, the bit corresponding to the first reading thread in the preset global variable can also be deleted. Then, based on the preset global variable, it can be determined that the first reading thread does not exist in the currently opened thread, that is, it is determined that the first reading thread has been closed.

[0091] In one implementation, when the first reading thread is closed, the handle of the first reading thread can be obtained, and the bit with the handle as the bit number in the preset global variable is deleted. For the above example, the value is specified as 1, and the bit corresponding to the first reading thread in the preset global variable is deleted, that is, the bit corresponding to the handle of the first reading thread in the preset global variable is changed to 0.

[0092] In one embodiment, if there are three pointer variables PointerA, PointerB, and PointerC, and the memory allocation function has been called to allocate memory space for each of them.

[0093] When the write thread calls the release function to release PointerA, it queries the first bitmap. At this time, the first bitmap is 0, that is, there is no opened read thread, so PointerA can be released directly.

[0094] When the read thread 1 calls the registration function, that is, the read thread 1 is started at this time, and the handle of the read thread 1 is 0, the first bitmap can be modified to 0x1.

[0095] When the write thread calls the release function to release PointerB, since the first bitmap is 0x1 at this time, indicating that there is an open read thread, 0x1 can be recorded in the second bitmap in the memory header corresponding to PointerB, and PointerB can be added to the linked list of pointer variables to be released.

[0096] When the read thread 2 calls the registration function, that is, the read thread 2 is started at this time, and the handle of the read thread 2 is 1, the first bitmap can be modified to 0x11.

[0097] When the write thread calls the release function to release PointerC, since the first bitmap is 0x11 at this time, indicating that there is an open read thread, 0x11 can be recorded in the second bitmap in the memory header corresponding to PointerC, and PointerC can be added to the linked list of pointer variables to be released.

[0098] When read thread 2 calls the deregistration function, that is, read thread 2 is closed at this time, and handle 1 of read thread 2 is obtained. The first bitmap is modified, and read thread 2 is deleted. The modified first bitmap is 0x1, and then the linked list of pointer variables to be released is traversed to determine that in the linked list of pointer variables to be released, the second bitmap corresponding to PointerC has a bit corresponding to handle 1, so the bit can be cleared, and the second bitmap is 0x1 after clearing.

[0099] When read thread 1 calls the deregistration function, that is, read thread 1 is closed at this time, and handle 0 of read thread 1 is obtained. The first bitmap is modified, and read thread 1 is deleted. The modified first bitmap is 0x0. Then, the linked list of pointer variables to be released is traversed to determine that in the linked list of pointer variables to be released, the second bitmap corresponding to PointerB and PointerC has the bit corresponding to handle 0, and the corresponding bits need to be cleared respectively. After clearing, the second bitmaps corresponding to PointerB and PointerC are both 0x0. In other words, PointerB and PointerC do not have corresponding read threads. At this time, PointerB and PointerC can be released.

[0100] Based on the above processing, for the pointer variable that needs to be released by the write thread, if there is currently an open read thread, the release of the pointer variable can be delayed, and the read thread corresponding to the pointer variable can be recorded, that is, the read thread that may access the pointer variable is recorded. Furthermore, when the read threads corresponding to the pointer variable are all closed, the pointer variable is released, and multiple read threads can access the pointer variable concurrently. In addition, since there is no need for additional locking to protect the pointer variable, even if the write thread is busy or hung due to a fault, it will not affect the read thread's access to data, and business interruption can be avoided.

[0101] Based on the same inventive concept, the present application embodiment also provides a pointer variable release device, see Figure 3 , Figure 3 A structural diagram of a pointer variable release device provided in an embodiment of the present application, the device comprising:

[0102] The pointer variable to be released determining module 301 is used for recording the mapping relationship between the first pointer variable and the currently opened reading thread when the writing thread needs to release the first pointer variable and there is currently an opened reading thread, and determining the first pointer variable as the pointer variable to be released;

[0103] A second pointer variable determination module 302 is used to determine a second pointer variable corresponding to the first reading thread among the pointer variables to be released when the opened first reading thread is closed;

[0104] A deleting module 303, configured to delete a mapping relationship between the second pointer variable and the first reading thread;

[0105] The first releasing module 304 is configured to release the second pointer variable if no corresponding reading thread exists for the second pointer variable in the currently recorded mapping relationship.

[0106] Optionally, the device further comprises:

[0107] The second releasing module is used to release the first pointer variable when the writing thread needs to release the first pointer variable and there is no currently opened reading thread.

[0108] Optionally, the to-be-released pointer variable determination module 301 includes:

[0109] The recording submodule is used to record the identifier of the currently opened reading thread in the memory space corresponding to the first pointer variable.

[0110] Optionally, the device further comprises:

[0111] A judgment module, configured to judge whether there is a bit with a specified value in a preset global variable before recording the mapping relationship between the first pointer variable and the currently opened read thread and determining the first pointer variable as the pointer variable to be released; wherein the preset global variable includes a plurality of bits, each bit corresponding to a read thread;

[0112] A first processing module, configured to determine that a currently opened read thread exists if a bit with a specified value exists in the preset global variable;

[0113] The second processing module is used to determine that there is no currently opened reading thread if there is no bit with a specified value in the preset global variable.

[0114] Optionally, the device further comprises:

[0115] The modification module is used to modify the bit corresponding to the second reading thread in the preset global variable to a specified value when the second reading thread is started.

[0116] Optionally, the device further comprises:

[0117] The deleting module is used to delete the bit corresponding to the first reading thread in the preset global variable when the opened first reading thread is closed.

[0118] The present application also provides an electronic device, such as Figure 4 As shown, it includes a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.

[0119] Memory 403, used for storing computer programs;

[0120] The processor 401 is used to execute the program stored in the memory 403 to implement the following steps:

[0121] When the write thread needs to release the first pointer variable and there is currently an opened read thread, a mapping relationship between the first pointer variable and the currently opened read thread is recorded, and the first pointer variable is determined as a pointer variable to be released;

[0122] When the opened first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the pointer variables currently to be released;

[0123] Deleting the mapping relationship between the second pointer variable and the first reading thread;

[0124] If there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, the second pointer variable is released.

[0125] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0126] The communication interface is used for communication between the above electronic device and other devices.

[0127] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0128] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0129] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned pointer variable release methods are implemented.

[0130] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any pointer variable releasing method in the above embodiments.

[0131] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0132] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0133] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0134] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A pointer variable release method, characterized in that: The method comprises: When the write thread needs to release the first pointer variable and there is currently an opened read thread, a mapping relationship between the first pointer variable and the currently opened read thread is recorded, and the first pointer variable is determined as a pointer variable to be released; When the opened first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the pointer variables currently to be released; Deleting the mapping relationship between the second pointer variable and the first reading thread; If there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship, the second pointer variable is released.

2. The method according to claim 1, characterized in that The method further comprises: When the write thread needs to release the first pointer variable and there is no currently opened read thread, the first pointer variable is released.

3. The method according to claim 1, characterized in that The recording of the mapping relationship between the first pointer variable and the currently opened read thread includes: The identifier of the currently opened read thread is recorded in the memory space corresponding to the first pointer variable.

4. The method according to claim 1, characterized in that Before recording the mapping relationship between the first pointer variable and the currently opened read thread and determining the first pointer variable as the pointer variable to be released, the method further includes: Determine whether there is a bit with a specified value in a preset global variable; wherein the preset global variable includes multiple bits, each bit corresponding to a read thread; If a bit with a specified value exists in the preset global variable, it is determined that a currently opened read thread already exists; If the bit with the specified value does not exist in the preset global variable, it is determined that there is no currently opened read thread.

5. The method according to claim 4, characterized in that The method further comprises: When the second reading thread is started, the bit corresponding to the second reading thread in the preset global variable is modified to a specified value.

6. The method according to claim 4, characterized in that The method further comprises: When the opened first reading thread is closed, the bit corresponding to the first reading thread in the preset global variable is deleted.

7. A pointer variable release device, characterized in that: The device comprises: A to-be-released pointer variable determination module, configured to, when a write thread needs to release a first pointer variable and a currently opened read thread already exists, record a mapping relationship between the first pointer variable and the currently opened read thread, and determine the first pointer variable as a to-be-released pointer variable; A second pointer variable determining module, configured to determine, when closing the opened first reading thread, a second pointer variable corresponding to the first reading thread in the current pointer variables to be released; A deleting module, used for deleting the mapping relationship between the second pointer variable and the first reading thread; The first releasing module is used to release the second pointer variable if there is no corresponding reading thread for the second pointer variable in the currently recorded mapping relationship.

8. The device according to claim 7, characterized in that The device also includes: The second releasing module is used to release the first pointer variable when the writing thread needs to release the first pointer variable and there is no currently opened reading thread.

9. The device according to claim 7, characterized in that The module for determining the pointer variable to be released includes: The recording submodule is used to record the identifier of the currently opened reading thread in the memory space corresponding to the first pointer variable.

10. The device according to claim 7, characterized in that The device also includes: A judgment module, used for judging whether there is a bit with a specified value in a preset global variable before recording the mapping relationship between the first pointer variable and the currently opened read thread and determining the first pointer variable as the pointer variable to be released; wherein the preset global variable includes a plurality of bits, each bit corresponding to a read thread; A first processing module, configured to determine that a currently opened read thread exists if a bit with a specified value exists in the preset global variable; The second processing module is used to determine that there is no currently opened reading thread if there is no bit with a specified value in the preset global variable.

11. The device according to claim 10, characterized in that The device also includes: The modification module is used to modify the bit corresponding to the second reading thread in the preset global variable to a specified value when the second reading thread is started.

12. The device according to claim 10, characterized in that The device also includes: The deleting module is used to delete the bit corresponding to the first reading thread in the preset global variable when the opened first reading thread is closed.

Citation Information

Patent Citations

  • Method and device for accessing shared data among multiple threads

    CN104216767A

  • Global variable using method, device and system and computer readable storage medium

    CN112596877A