CN113656111A - Pointer variable release method and device - Google Patents

Pointer variable release method and device Download PDF

Info

Publication number
CN113656111A
CN113656111A CN202111039845.8A CN202111039845A CN113656111A CN 113656111 A CN113656111 A CN 113656111A CN 202111039845 A CN202111039845 A CN 202111039845A CN 113656111 A CN113656111 A CN 113656111A
Authority
CN
China
Prior art keywords
pointer variable
thread
variable
pointer
currently
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111039845.8A
Other languages
Chinese (zh)
Inventor
杨益泉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
New H3C Security Technologies Co Ltd
Original Assignee
New H3C Security Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by New H3C Security Technologies Co Ltd filed Critical New H3C Security Technologies Co Ltd
Priority to CN202111039845.8A priority Critical patent/CN113656111A/en
Publication of CN113656111A publication Critical patent/CN113656111A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44594Unloading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Storage Device Security (AREA)

Abstract

The embodiment of the application provides a pointer variable release method and a device, which relate to the technical field of computers, and the method comprises the following steps: when the write thread needs to release the first pointer variable and an opened read thread exists currently, recording a mapping relation between the first pointer variable and the opened read thread currently, and determining the first pointer variable as a pointer variable to be released; when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released; deleting the mapping relation between the second pointer variable and the first reading thread; and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable. Therefore, the service interruption can be avoided under the condition that a plurality of reading threads access the pointer variable simultaneously.

Description

Pointer variable release method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for releasing a pointer variable.
Background
During the running of the application program, data can be accessed through a plurality of threads. For example, in an application program based on C language, data can be written to a pointer variable by a write thread, and data can be read from the pointer variable by a read thread.
In the related art, concurrent access of threads is implemented based on locks. For example, a thread may need to acquire a lock before performing a read or write access. After successfully acquiring the lock, the thread may access the corresponding data. After the lock is successfully acquired, if the thread is abnormal and cannot release the lock at all times, other threads cannot access the data because the thread cannot acquire the lock, and service interruption is caused.
Disclosure of Invention
An object of the embodiments of the present application is to provide a pointer variable release method and apparatus, which can avoid service interruption when multiple read threads concurrently access a pointer variable. The specific technical scheme is as follows:
in a first aspect, to achieve the above object, an embodiment of the present application discloses a pointer variable release method, where the method includes:
when a write thread needs to release a first pointer variable and an opened read thread exists currently, recording a mapping relation between the first pointer variable and the opened read thread currently, and determining the first pointer variable as a pointer variable to be released;
when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released;
deleting the mapping relation between the second pointer variable and the first reading thread;
and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable.
Optionally, the method further includes:
and when the write thread needs to release the first pointer variable and no open read thread exists currently, releasing the first pointer variable.
Optionally, the recording a mapping relationship between the first pointer variable and a currently started read thread includes:
and recording the identifier of the currently started read thread in the memory space corresponding to the first pointer variable.
Optionally, before the recording a mapping relationship between the first pointer variable and a currently started read thread, and determining the first pointer variable as a pointer variable to be released, the method further includes:
judging whether a bit of a designated numerical value exists in a preset global variable; the preset global variable comprises a plurality of bits, and each bit corresponds to one read thread;
if the bit of the designated numerical value exists in the preset global variable, determining that the opened reading thread exists currently;
and if the bit of the designated numerical value does not exist in the preset global variable, determining that the opened read thread does not exist currently.
Optionally, the method further includes:
and when a second reading thread is started, modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value.
Optionally, the method further includes:
and when the started first reading thread is closed, deleting a bit corresponding to the first reading thread in the preset global variable.
In a second aspect, in order to achieve the above object, an embodiment of the present application discloses a pointer variable release apparatus, including:
the device comprises a to-be-released pointer variable determining module, a to-be-released pointer variable determining module and a to-be-released pointer variable determining module, wherein the to-be-released pointer variable determining module is used for recording a mapping relation between a first pointer variable and a currently opened read thread when a write thread needs to release the first pointer variable and the currently opened read thread exists, and determining the first pointer variable as the to-be-released pointer variable;
the second pointer variable determining module is used for determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released when the started first reading thread is closed;
a deleting module, configured to delete a mapping relationship between the second pointer variable and the first read thread;
and the first releasing module is used for releasing the second pointer variable if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation.
Optionally, the apparatus further comprises:
and the second releasing module is used for releasing the first pointer variable when the write thread needs to release the first pointer variable and no open read thread exists currently.
Optionally, the pointer to be released variable determining module includes:
and the recording submodule is used for recording the identification of the currently opened reading thread in the memory space corresponding to the first pointer variable.
Optionally, the apparatus further comprises:
the judging module is used for judging whether a bit of a specified numerical value exists in a preset global variable before recording the mapping relation between the first pointer variable and the currently started reading thread and determining the first pointer variable as a pointer variable to be released; the preset global variable comprises a plurality of bits, and each bit corresponds to one read thread;
the first processing module is used for determining that an opened reading thread exists currently if a bit of a specified numerical value exists in the preset global variable;
and the second processing module is used for determining that no open read thread exists currently if the bit of the designated numerical value does not exist in the preset global variable.
Optionally, the apparatus further comprises:
and the modifying module is used for modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value when the second reading thread is started.
Optionally, the apparatus further comprises:
and the deleting module is used for deleting the bit corresponding to the first reading thread in the preset global variable when the started first reading thread is closed.
In another aspect of this application, in order to achieve the above object, an embodiment of this application further discloses an electronic device, where the electronic device includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the pointer variable release method according to the first aspect when executing the program stored in the memory.
In yet another aspect of this application implementation, there is further provided a computer-readable storage medium having stored therein a computer program, which when executed by a processor, implements the pointer variable release method as described in the above first aspect.
In another aspect of this embodiment, a computer program product containing instructions is provided, which when executed on a computer, causes the computer to execute the pointer variable release method according to the first aspect.
The embodiment of the application has the following beneficial effects:
according to the pointer variable release method provided by the embodiment of the application, when a write thread needs to release a first pointer variable and an opened read thread exists currently, a mapping relation between the first pointer variable and the opened read thread is recorded, and the first pointer variable is determined as a pointer variable to be released; when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released; deleting the mapping relation between the second pointer variable and the first reading thread; and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable.
Based on the above processing, for a pointer variable that needs to be released by a write thread, if there is an open read thread currently, the release of the pointer variable may be delayed, and a read thread corresponding to the pointer variable, that is, a read thread that may access the pointer variable, may be recorded. Furthermore, when the read threads corresponding to the pointer variable are all closed, the pointer variable is released, so that the pointer variable can be accessed by a plurality of read threads simultaneously. In addition, because the variable of the protection pointer does not need to be additionally locked, even if the write thread is busy or hung due to a fault, the read thread is not influenced to access data, and the service interruption can be avoided.
Of course, not all advantages described above need to be achieved at the same time in the practice of any one product or method of the present application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present application, and it is also obvious for a person skilled in the art to obtain other embodiments according to the drawings.
Fig. 1 is a flowchart of a pointer variable release method according to an embodiment of the present application;
fig. 2 is a flowchart of another pointer variable release method according to an embodiment of the present application;
fig. 3 is a structural diagram of a pointer variable release device according to an embodiment of the present application;
fig. 4 is a structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments that can be derived by one of ordinary skill in the art from the description herein are intended to be within the scope of the present disclosure.
The embodiment of the application provides a pointer variable release method, which can be applied to electronic equipment, and the electronic equipment can run an application program based on C language. During the process of running the application program, the electronic device can access the data stored in the memory space indicated by the pointer variable through the thread. Correspondingly, when the access is finished, the delayed release of the pointer variable can be realized according to the requirement, namely, the memory space corresponding to the pointer variable is released.
Referring to fig. 1, fig. 1 is a flowchart of a pointer variable release method provided in an embodiment of the present application, where the method may include the following steps:
s101: when the write thread needs to release the first pointer variable and an opened read thread exists currently, recording a mapping relation between the first pointer variable and the opened read thread currently, and determining the first pointer variable as a pointer variable to be released.
S102: and when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released.
S103: and deleting the mapping relation between the second pointer variable and the first reading thread.
S104: and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable.
According to the pointer variable release method provided by the embodiment of the application, for the pointer variable to be released by the write thread, under the condition that an open read thread exists at present, the pointer variable can be released in a delayed manner, and the read thread corresponding to the pointer variable can be recorded, that is, the read thread which 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, so that the pointer variable can be accessed by a plurality of read threads simultaneously. The method can effectively support the scene that one writing thread and a plurality of reading threads are concurrent. In addition, because the pointer variable is protected without being additionally locked, even if the write thread is busy or hung due to a fault, the read thread access data is not influenced, the service interruption can be avoided, and the operation and maintenance management and the fault location are facilitated.
For step S101, the writer thread needs to release the first pointer variable. For example, if a network change causes a need to delete a routing table entry, a pointer variable corresponding to the routing table entry needs to be released. In one implementation, the write thread may 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.
At this time, the electronic device may determine whether there is an open read thread currently. If there is an open read thread, the open read thread may read the data in the memory space pointed to by the first pointer variable, and thus the first pointer variable is not currently released.
The electronic device may record a mapping relationship between the first pointer variable and a currently opened read thread, that is, the electronic device may record a read thread that may currently access the first pointer variable.
In one embodiment, the electronic device may add the first pointer variable to a preset linked list (which may be referred to as a to-be-released pointer variable linked list) to determine the first pointer variable as the to-be-released pointer variable.
With respect to step S102, the first read thread has completed accessing the pointer variable, at which time the first read thread may be turned off. In one implementation, when the first read thread is started, a registration function may be called by the first read thread to register, and thus, a pointer variable may be accessed. Correspondingly, when the first reading thread finishes the access aiming at the pointer variable, a logout function is called through the first reading thread to carry out logout. At this time, the electronic device may turn off the first read thread.
Then, the electronic device may perform a query in the pointer variable to be currently released to determine whether a pointer variable (i.e., a second pointer variable) corresponding to the first read thread exists. The determined second pointer variable may be one or more.
If the second pointer variable exists, since the first read thread is closed at this time, step S103 may be executed to delete the mapping relationship between the second pointer variable and the first read thread, that is, determine that the second pointer variable no longer corresponds to the first read thread. That is, there is no first read thread among the read threads currently accessing the second pointer variable.
For step S104, for each second pointer variable, the read thread corresponding to the second pointer variable in the recorded mapping relationship indicates a read thread that may currently access the second pointer variable. Therefore, after deleting the mapping relationship between the second pointer variable and the first read thread, if there is no corresponding read thread for the second pointer variable in the currently recorded mapping relationship, it indicates that there is no read thread for accessing the second pointer variable currently, and further, the second pointer variable may be released, that is, the memory space pointed by the second pointer variable is released.
In one embodiment, the method may further comprise the steps of:
and when the write thread needs to release the first pointer variable and no open read thread exists currently, releasing the first pointer variable.
In this embodiment, when the write thread needs to release the first pointer variable, if there is no open read thread currently, it indicates that there is no read thread currently accessing the first pointer variable, and further, the first pointer variable may be directly released, that is, the memory space pointed by the first pointer variable is released.
In one embodiment, before the step S101, the method may further include the steps of:
the method comprises the following steps: and judging whether the bits of the designated numerical value exist in the preset global variable.
Step two: and if the bit of the designated numerical value exists in the preset global variable, determining that the opened read thread exists currently.
Step three: and if the bit of the designated numerical value does not exist in the preset global variable, determining that the opened read thread does not exist currently.
The preset global variable comprises a plurality of bits, and each bit corresponds to one read thread. One bit is a designated value indicating that the read thread corresponding to the bit is open.
In the embodiment of the present application, a global variable may be preset, and the global variable may include a plurality of bits. In one implementation, the global variable may be represented by a global data structure, e.g., a global BitMap (which may be referred to as a first BitMap).
In one implementation, if there is no open read thread currently, the first bitmap may be 0; if a new read thread is started, a handle 0 can be allocated to the read thread, which represents the bit number of the corresponding bit in the first bitmap, and the first bitmap is modified to 0x1, that is, the bit with the bit number of 0 in the first bitmap is modified to 1; similarly, if another new read thread is started, a handle 1 may be allocated to the new read thread, which indicates the bit number of the corresponding bit in the first bitmap, and the first bitmap is modified to 0x11, that is, the bit with bit number 1 in the first bitmap is modified to 1.
The value is 1 in the above example, that is, if there is a bit of 1 in the preset global variable, it indicates that there is an opened read thread currently, and the bit number of the bit of 1 is the handle of the opened read thread.
In one embodiment, referring to fig. 2, on the basis of fig. 1, the step S101 may include:
s1011: when the write thread needs to release the first pointer variable and an opened read thread exists currently, recording the identifier of the opened read thread currently in a memory space corresponding to the first pointer variable, and determining the first pointer variable as a pointer variable to be released.
In this embodiment of the application, the electronic device may allocate a memory space to the pointer variable through a memory allocation function, and accordingly, the allocated memory space may additionally allocate a header, in addition to storing the data represented by the first pointer variable, for recording an identifier of a read thread corresponding to the first pointer variable. The identity of the read thread may be represented by its handle.
In one implementation, a data structure corresponding to the first pointer variable may be recorded in the header, and may be, for example, BitMap, which may be referred to as a second BitMap. Based on the second bitmap, an identification of a read thread corresponding to the first pointer variable may be recorded.
For example, the electronic device may query the first bitmap, and record a value of the first bitmap in a second bitmap corresponding to a first pointer variable, where each bit in the second bitmap represents a read thread corresponding to the first pointer variable, and a bit number of each bit is a handle of the corresponding read thread.
In one embodiment, the method may further comprise the steps of:
and when the second reading thread is started, modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value.
In the embodiment of the present application, if a new read thread (i.e., a second read thread) is started, bits corresponding to the second read thread in the preset global variable may be modified to a specified value. For example, a handle of the second read thread may be determined, and a bit corresponding to the handle in the preset global variable may be modified to a specified value. Furthermore, by using the preset global variable, it may be determined that a second read thread is currently started, and an identifier of the second read thread may be recorded in a memory space corresponding to a second pointer variable, so as to indicate that the second read thread may access the pointer variable.
In one embodiment, the method may further comprise the steps of:
and when the started first reading thread is closed, deleting a bit corresponding to the first reading thread in the preset global variable.
In this embodiment of the application, when the first read thread is closed, a bit corresponding to the first read thread in the preset global variable may be deleted, and further, based on the preset global variable, it may be determined that the first read thread does not exist in the currently opened thread, that is, it is determined that the first read thread is closed.
In one implementation, when the first read thread is closed, a handle of the first read thread may be obtained, and a bit with the handle as a bit number in the preset global variable may be deleted. For the above example, the value is designated as 1, and the bit corresponding to the first read thread in the preset global variable is deleted, that is, the bit corresponding to the handle of the first read thread in the preset global variable is modified to 0.
In one embodiment, if there are three pointer variables PointerA, PointerB, and PointerC, and a memory allocation function has been invoked to allocate memory space for each.
When the write thread calls a release function to release PointerA, the first bitmap is inquired. At this time, the first bitmap is 0, i.e., there is no open read thread, so PointerA can be released directly.
When read thread 1 calls the registration function, i.e., when read thread 1 is turned on, the handle of read thread 1 is 0, the first bitmap may be modified to 0x 1.
When the write thread calls the release function to release PointerB, since the first bitmap is 0x1 at this time, which indicates that there is an open read thread, 0x1 may be recorded in the second bitmap in the memory header corresponding to PointerB, and PointerB is added to the variable linked list of the pointer to be released.
When read thread 2 calls the registration function, i.e., when read thread 2 is turned on, the handle of read thread 2 is 1, the first bitmap may be modified to 0x 11.
When the write thread calls the release function to release PointerC, since the first bitmap is 0x11 at this time, which indicates that there is an open read thread, 0x11 may be recorded in the second bitmap in the memory header corresponding to PointerC, and PointerC is added to the variable linked list of the pointer to be released.
When the read thread 2 calls the logout function, namely, the read thread 2 is closed at the moment, and the handle 1 of the read thread 2 is acquired. Modifying the first bitmap, deleting the read thread 2, wherein the modified first bitmap is 0x1, traversing the variable linked list of the pointer to be released, and determining that a bit corresponding to the handle 1 exists in the second bitmap corresponding to the PointC in the variable linked list of the pointer to be released, so that the bit can be cleared, and the second bitmap is 0x1 after clearing.
When the read thread 1 calls the logout function, that is, the read thread 1 is closed at this time, and the handle 0 of the read thread 1 is acquired. Modifying the first bitmap, deleting the read thread 1, wherein the modified first bitmap is 0x0, traversing the pointer variable linked list to be released, determining that the bit corresponding to the handle 0 exists in the second bitmap corresponding to PointerB and PointerC in the pointer variable linked list to be released, and respectively clearing the corresponding bit. After the clearing, the second bitmaps corresponding to PointerB and PointerC are both 0x 0. That is to say, no corresponding read thread exists between PointerB and PointerC, and at this time, PointerB and PointerC can be released.
Based on the above processing, for a pointer variable that needs to be released by a write thread, if there is an open read thread currently, the release of the pointer variable may be delayed, and a read thread corresponding to the pointer variable, that is, a read thread that may access the pointer variable, may be recorded. Furthermore, when the read threads corresponding to the pointer variable are all closed, the pointer variable is released, so that the pointer variable can be accessed by a plurality of read threads simultaneously. In addition, because the variable of the protection pointer does not need to be additionally locked, even if the write thread is busy or hung due to a fault, the read thread is not influenced to access data, and the service interruption can be avoided.
Based on the same inventive concept, an embodiment of the present application further provides a pointer variable release device, referring to fig. 3, where fig. 3 is a structural diagram of the pointer variable release device provided in the embodiment of the present application, and the device includes:
a to-be-released pointer variable determining module 301, configured to record, when a write thread needs to release a first pointer variable and there is an open read thread currently, a mapping relationship between the first pointer variable and the open read thread currently, and determine the first pointer variable as the to-be-released pointer variable;
a second pointer variable determining module 302, configured to determine, when the started first read thread is closed, a second pointer variable corresponding to the first read thread in the current pointer variables to be released;
a deleting module 303, configured to delete a mapping relationship between the second pointer variable and the first read thread;
a first releasing module 304, configured to release the second pointer variable if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relationship.
Optionally, the apparatus further comprises:
and the second releasing module is used for releasing the first pointer variable when the write thread needs to release the first pointer variable and no open read thread exists currently.
Optionally, the pointer to be released variable determining module 301 includes:
and the recording submodule is used for recording the identification of the currently opened reading thread in the memory space corresponding to the first pointer variable.
Optionally, the apparatus further comprises:
the judging module is used for judging whether a bit of a specified numerical value exists in a preset global variable before recording the mapping relation between the first pointer variable and the currently started reading thread and determining the first pointer variable as a pointer variable to be released; the preset global variable comprises a plurality of bits, and each bit corresponds to one read thread;
the first processing module is used for determining that an opened reading thread exists currently if a bit of a specified numerical value exists in the preset global variable;
and the second processing module is used for determining that no open read thread exists currently if the bit of the designated numerical value does not exist in the preset global variable.
Optionally, the apparatus further comprises:
and the modifying module is used for modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value when the second reading thread is started.
Optionally, the apparatus further comprises:
and the deleting module is used for deleting the bit corresponding to the first reading thread in the preset global variable when the started first reading thread is closed.
The embodiment of the present application further provides an electronic device, as shown in fig. 4, which includes a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401, when executing the program stored in the memory 403, implements the following steps:
when a write thread needs to release a first pointer variable and an opened read thread exists currently, recording a mapping relation between the first pointer variable and the opened read thread currently, and determining the first pointer variable as a pointer variable to be released;
when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released;
deleting the mapping relation between the second pointer variable and the first reading thread;
and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
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 memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In yet another embodiment provided by the present application, a computer-readable storage medium is further provided, in which a computer program is stored, and the computer program, when executed by a processor, implements the steps of any of the pointer variable release methods described above.
In yet another embodiment provided by the present application, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the pointer variable release methods of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may 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 loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the application to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, 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, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present application and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims (12)

1. A method for pointer variable release, the method comprising:
when a write thread needs to release a first pointer variable and an opened read thread exists currently, recording a mapping relation between the first pointer variable and the opened read thread currently, and determining the first pointer variable as a pointer variable to be released;
when the started first reading thread is closed, determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released;
deleting the mapping relation between the second pointer variable and the first reading thread;
and if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation, releasing the second pointer variable.
2. The method of claim 1, further comprising:
and when the write thread needs to release the first pointer variable and no open read thread exists currently, releasing the first pointer variable.
3. The method of claim 1, wherein the recording a mapping relationship between the first pointer variable and a currently started read thread comprises:
and recording the identifier of the currently started read thread in the memory space corresponding to the first pointer variable.
4. The method according to claim 1, wherein before the recording of the mapping relationship between the first pointer variable and the currently opened read thread and the determining of the first pointer variable as the pointer variable to be released, the method further comprises:
judging whether a bit of a designated numerical value exists in a preset global variable; the preset global variable comprises a plurality of bits, and each bit corresponds to one read thread;
if the bit of the designated numerical value exists in the preset global variable, determining that the opened reading thread exists currently;
and if the bit of the designated numerical value does not exist in the preset global variable, determining that the opened read thread does not exist currently.
5. The method of claim 4, further comprising:
and when a second reading thread is started, modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value.
6. The method of claim 4, further comprising:
and when the started first reading thread is closed, deleting a bit corresponding to the first reading thread in the preset global variable.
7. A pointer variable release apparatus, the apparatus comprising:
the device comprises a to-be-released pointer variable determining module, a to-be-released pointer variable determining module and a to-be-released pointer variable determining module, wherein the to-be-released pointer variable determining module is used for recording a mapping relation between a first pointer variable and a currently opened read thread when a write thread needs to release the first pointer variable and the currently opened read thread exists, and determining the first pointer variable as the to-be-released pointer variable;
the second pointer variable determining module is used for determining a second pointer variable corresponding to the first reading thread in the current pointer variables to be released when the started first reading thread is closed;
a deleting module, configured to delete a mapping relationship between the second pointer variable and the first read thread;
and the first releasing module is used for releasing the second pointer variable if the second pointer variable does not have a corresponding read thread in the currently recorded mapping relation.
8. The apparatus of claim 7, further comprising:
and the second releasing module is used for releasing the first pointer variable when the write thread needs to release the first pointer variable and no open read thread exists currently.
9. The apparatus of claim 7, wherein the to-be-released pointer variable determining module comprises:
and the recording submodule is used for recording the identification of the currently opened reading thread in the memory space corresponding to the first pointer variable.
10. The apparatus of claim 7, further comprising:
the judging module is used for judging whether a bit of a specified numerical value exists in a preset global variable before recording the mapping relation between the first pointer variable and the currently started reading thread and determining the first pointer variable as a pointer variable to be released; the preset global variable comprises a plurality of bits, and each bit corresponds to one read thread;
the first processing module is used for determining that an opened reading thread exists currently if a bit of a specified numerical value exists in the preset global variable;
and the second processing module is used for determining that no open read thread exists currently if the bit of the designated numerical value does not exist in the preset global variable.
11. The apparatus of claim 10, further comprising:
and the modifying module is used for modifying the bit corresponding to the second reading thread in the preset global variable into a specified numerical value when the second reading thread is started.
12. The apparatus of claim 10, further comprising:
and the deleting module is used for deleting the bit corresponding to the first reading thread in the preset global variable when the started first reading thread is closed.
CN202111039845.8A 2021-09-06 2021-09-06 Pointer variable release method and device Pending CN113656111A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111039845.8A CN113656111A (en) 2021-09-06 2021-09-06 Pointer variable release method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111039845.8A CN113656111A (en) 2021-09-06 2021-09-06 Pointer variable release method and device

Publications (1)

Publication Number Publication Date
CN113656111A true CN113656111A (en) 2021-11-16

Family

ID=78482910

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111039845.8A Pending CN113656111A (en) 2021-09-06 2021-09-06 Pointer variable release method and device

Country Status (1)

Country Link
CN (1) CN113656111A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198519A1 (en) * 2006-02-22 2007-08-23 David Dice Methods and apparatus to implement parallel transactions
CN101631328A (en) * 2009-08-14 2010-01-20 北京星网锐捷网络技术有限公司 Synchronous method performing mutual exclusion access on shared resource, device and network equipment
CN104216767A (en) * 2014-09-18 2014-12-17 东软集团股份有限公司 Method and device for accessing shared data among multiple threads
US20150213105A1 (en) * 2012-10-11 2015-07-30 Tencent Technology (Shenzhen) Company Limited Data processing method, apparatus, and storage medium
CN109947575A (en) * 2019-03-21 2019-06-28 恒生电子股份有限公司 Locking, method for releasing and the related system of Read-Write Locks
CN112596877A (en) * 2020-12-18 2021-04-02 深圳Tcl新技术有限公司 Global variable using method, device, system and computer readable storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198519A1 (en) * 2006-02-22 2007-08-23 David Dice Methods and apparatus to implement parallel transactions
CN101631328A (en) * 2009-08-14 2010-01-20 北京星网锐捷网络技术有限公司 Synchronous method performing mutual exclusion access on shared resource, device and network equipment
US20150213105A1 (en) * 2012-10-11 2015-07-30 Tencent Technology (Shenzhen) Company Limited Data processing method, apparatus, and storage medium
CN104216767A (en) * 2014-09-18 2014-12-17 东软集团股份有限公司 Method and device for accessing shared data among multiple threads
CN109947575A (en) * 2019-03-21 2019-06-28 恒生电子股份有限公司 Locking, method for releasing and the related system of Read-Write Locks
CN112596877A (en) * 2020-12-18 2021-04-02 深圳Tcl新技术有限公司 Global variable using method, device, system and computer readable storage medium

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
TANG WENJIE等: "A hierarchical parallel discrete event simulation kernel for multicore platform", 《CLUSTER COMPUTING-THE JOURNAL OF NETWORKS SOFTWARE TOOLS AND APPLICATIONS》, 4 September 2013 (2013-09-04) *
余翔湛, 殷丽华: "动态共享内存缓冲池技术", 哈尔滨工业大学学报, no. 03, 30 March 2004 (2004-03-30) *
游理通: "一个基于日志结构的非易失性内存键值存储系统", 《计算机研究与发展》, 30 September 2018 (2018-09-30) *

Similar Documents

Publication Publication Date Title
US8627323B2 (en) Utilizing user-defined workflow policies to automate changes made to composite workflows
CN108897628B (en) Method and device for realizing distributed lock and electronic equipment
CN108255620B (en) Service logic processing method, device, service server and system
US9514170B1 (en) Priority queue using two differently-indexed single-index tables
CN111382206B (en) Data storage method and device
CN108573019B (en) Data migration method and device, electronic equipment and readable storage medium
CN109977261B (en) Data request processing method and device and server
KR102254159B1 (en) Method for detecting real-time error in operating system kernel memory
CN112463058B (en) Fragmented data sorting method and device and storage node
CN113407376A (en) Data recovery method and device and electronic equipment
JP2005302030A (en) Multi-process access method and device to link list
CN113656111A (en) Pointer variable release method and device
CN108388424B (en) Method and device for calling interface data and electronic equipment
CN116302598A (en) Shared memory processing method and device, computer equipment and storage medium
CN113438245B (en) Information updating and message security detection method and device
CN115865839A (en) ACL management method, device, communication equipment and storage medium
CN112783954B (en) Data access method, device and server
CN110543486B (en) Data change method and device and server
CN113687921A (en) Transaction processing method and device, distributed database system and electronic equipment
JP7049275B2 (en) Diagnostic data capture
CN114647663A (en) Resource processing method, device and system, electronic equipment and storage medium
CN113157513B (en) Heap memory damage detection method and device, electronic equipment and storage medium
CN112882867B (en) Index information storage method and device and storage equipment
US11533315B2 (en) Data transfer discovery and analysis systems and related methods
CN111158701B (en) Library module issuing method, device, equipment and storage medium

Legal Events

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