CN115858186A - Shared resource access method, system, electronic device and storage medium - Google Patents
Shared resource access method, system, electronic device and storage medium Download PDFInfo
- Publication number
- CN115858186A CN115858186A CN202211715382.7A CN202211715382A CN115858186A CN 115858186 A CN115858186 A CN 115858186A CN 202211715382 A CN202211715382 A CN 202211715382A CN 115858186 A CN115858186 A CN 115858186A
- Authority
- CN
- China
- Prior art keywords
- linked list
- target node
- node
- target
- locking
- 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
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a shared resource access method, a system, electronic equipment and a storage medium, and relates to the field of communication. The shared resource access method comprises the following steps: acquiring a linked list of resources to be accessed; wherein, the linked list comprises a plurality of nodes; traversing the linked list and judging whether the target node can be found in the linked list or not; the target section comprises a node corresponding to the target access resource; if the target node cannot be found in the linked list, locking the linked list to obtain a locked linked list; traversing the locking linked list, and judging whether the target node can be found in the locking linked list or not; and if the target node can be found in the locking linked list, accessing the target node. By using the shared resource access method provided by the embodiment of the application, the problem of the reduction of the concurrent execution capacity of the program caused by locking and traversing the resource can be solved, and the access rate of the program to the shared resource and the concurrent processing capacity of the program are improved.
Description
Technical Field
The present application relates to the field of communications, and in particular, to a method, a system, an electronic device, and a storage medium for accessing a shared resource.
Background
Under a high concurrency scene, when a multi-core process accesses the same shared resource at the same time, the shared resource is often protected in order to avoid the multi-process synchronization problems of dirty reading, repeated adding, memory treading and the like.
At present, a common method for sharing resources by a locking protection method generally traverses shared resources by locking, and the locking generally comprises a self-locking or a read-write locking; the spin lock means that when a thread acquires a lock, if the lock is acquired by other threads, the thread waits circularly, and then continuously judges whether the lock can be acquired successfully or not, and the cycle can be exited until the lock is acquired; the read-write lock is a special spin lock, and divides an accessor for sharing resources into a reader and a writer, wherein the reader only performs read access on the sharing resources, and the writer needs to perform write operation on the sharing resources.
However, when accessing the shared resource, the lock operation is directly performed on the shared resource, which causes that only a single process can access the same resource at the same time, the multi-core process is executed serially, and the concurrent execution capability of the program is reduced.
Disclosure of Invention
An embodiment of the present application aims to provide a method, a system, an electronic device, and a storage medium for accessing a shared resource, which solve the problem that, due to lock protection on the shared resource, the shared resource can only be accessed by the same process at the same time, and parallel access to the shared resource by a multi-core device is changed into serial access, so that the concurrency performance of a program is greatly reduced.
In a first aspect, an embodiment of the present application provides a shared resource access method, where the method includes: obtaining
A linked list of resources to be accessed; wherein, the linked list comprises a plurality of nodes; traversing the linked list, and judging whether the target node can be found in the linked list or not; the target section comprises a node corresponding to the target access resource; if it is
If the target node cannot be found in the linked list, locking the linked list to obtain a locked linked list; traversing the locking linked list, and judging whether the target node can be found in the locking linked list or not; and if the target node can be found in the locking linked list, accessing the target node.
In the implementation process, in order to access the target 0-object resource, the shared resource access method provided by the embodiment of the application firstly acquires the linked list to be accessed, and then acquires the linked list of the resource to be accessed; the linked list is traversed and,
judging whether the target node can be found in the linked list or not; if the target node cannot be found, locking the shared resource, and traversing the linked list again after locking; if the target node is found, the target resource can be accessed. Therefore, the shared resource access method provided by the embodiment of the application can avoid resource consumption caused by locking to a certain extent, and can improve the concurrency performance of the program.
Optionally, in this embodiment of the present application, the linked list is traversed, and it is determined whether the linked list can be looked up
The target node comprises: acquiring a target node element of a target node; starting from the initial node of the linked list, searching a target node according to the node element of the target node to the last node of the linked list; and judging whether the target node with the node element consistent with the target node element can be found in the linked list or not.
In the implementation process, in order to search the target node in the linked list, all nodes in the linked list are traversed from the first node of the linked list by acquiring the 0 node element of the target node, and each node is used
Comparing the node elements of the point with the node elements of the target node, and judging whether the target node can be found from the linked list or not; therefore, by using the shared resource access method provided by the embodiment of the application, when the linked list is traversed for the first time, the conclusion whether the target node exists in the linked list can be obtained, and the condition that the multi-core program cannot run in parallel due to direct locking traversal cannot be caused.
Optionally, in this embodiment of the present application, locking the linked list to obtain a locked linked list includes: acquiring an updating instruction of the linked list, and locking the linked list according to the updating instruction; wherein, the lock comprises a read-write lock and a spin lock; the linked list is updated to obtain a locked linked list.
In the implementation process, under the condition that the target node is not found successfully in the first lock-free traversal, the shared resource is locked again; and after the update instruction of the linked list is acquired, locking the linked list according to the update instruction, and updating the linked list after locking, thereby acquiring the locked shared resource. The shared resource serial access caused by locking traversal in the first traversal is avoided, and the concurrent execution capacity of the program can be improved.
Optionally, in this embodiment of the present application, the shared resource access method further includes: if the target node can be found in the linked list, the address of the target node is obtained; and accessing the target access resource according to the address of the target node.
In the implementation process, when the target node can be found in the linked list in the first traversal, the address of the target node is obtained, and the target access resource is accessed according to the address of the target node. It should be understood that the processes may be performed concurrently during the first pass; in addition, as the operation of adding nodes in the linked list is few, most of the cases only need to execute the first traversal; therefore, serial access of shared resources can be only caused under fewer conditions by using the shared resource access method provided by the embodiment of the application, and running resources are saved while the multi-process synchronization problems of dirty reading, repeated adding, memory treading and the like are avoided.
Optionally, in an embodiment of the present application, the method for accessing a shared resource further includes: if the target node cannot be found in the locked linked list, creating the target node and hanging the target node on the linked list; and accessing the target access resource according to the target node.
In the implementation process, after the second locking traversal, if the target node still cannot be found from the linked list, the shared resource access method provided in the embodiment of the present application needs to create a node and mount the created node on the linked list, thereby implementing access to the target resource. Therefore, the shared resource access method provided by the embodiment of the application can protect the linked list from generating the problems of dirty reading, repeated adding, memory treading and the like of a program under the condition that the linked list needs to be modified.
Optionally, in this embodiment of the present application, creating a target node, and loading the target node on a linked list includes: configuring a target storage space for a target node; creating a target node and acquiring the address of the target node; and inserting the target node into the target storage space according to the address of the target node so as to mount the target node on the linked list.
In the implementation process, in order to create the target node and mount the target node on the linked list, a storage space needs to be configured for the target node first, and the target node is inserted into the linked list according to the address of the target node, so that the creation of the node is implemented.
Optionally, in this embodiment of the present application, after inserting the target node into the target storage space according to the address of the target node to mount the target node on the linked list, the method further includes: the linked list is updated to obtain a linked list that includes the target nodes.
In the implementation process, in the shared resource access method provided in the embodiment of the present application, after the target node is created, the target node is inserted into the target storage space according to the address of the target node, and then the linked list to which the target node is added is updated, so that the linked list including the target node is obtained; the creation of the node is completed, and the process can smoothly access the target resource.
In a second aspect, an embodiment of the present application provides a shared resource access system, where the shared resource access system includes: the system comprises a linked list acquisition module, a target node searching module, a locking module and a target node access module: the linked list acquisition module is used for acquiring a linked list of resources to be accessed; wherein, the linked list comprises a plurality of nodes; the target node searching module is used for traversing the linked list and judging whether the target node can be searched in the linked list or not; the target section comprises a node corresponding to the target access resource; the locking module is used for locking the linked list when the target node cannot be found in the linked list so as to obtain a locked linked list; the target node searching module is also used for traversing the locking linked list and judging whether the target node can be searched in the locking linked list or not; and the target node access module is used for accessing the target node when the target node is found in the locking linked list.
In a third aspect, an embodiment of the present application provides an electronic device, where the electronic device includes a memory and a processor, where the memory stores program instructions, and the processor executes the steps in any one of the foregoing implementation manners when reading and executing the program instructions.
In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, where computer program instructions are stored in the computer-readable storage medium, and when the computer program instructions are read and executed by a processor, the steps in any of the foregoing implementation manners are performed.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a flowchart of a first access process of a shared resource according to an embodiment of the present application;
fig. 2 is a flowchart of searching for a target node according to an embodiment of the present application;
FIG. 3 is a schematic diagram illustrating a generation of a locked chain table according to an embodiment of the present application;
FIG. 4 is a second flowchart of accessing a shared resource according to an embodiment of the present application;
fig. 5 is a flowchart of node creation provided in the embodiment of the present application;
FIG. 6 is a flow chart of a preferred embodiment provided herein;
FIG. 7 is a block diagram of a shared resource access system according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed description of the preferred embodiments
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. For example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard,
each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved
Depending on the function of the system. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based computer systems that perform the specified functions or acts
A system of parts, or may be implemented using a combination of dedicated hardware and computer instructions. In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The applicant 0 finds in the research process that the multi-core process simultaneously accesses the same share under the high concurrency scene
During resource sharing, in order to avoid the problem of multi-process synchronization such as dirty reading, repeated addition, memory treading and the like, a lock is required to protect shared resources. Common ways to lock a shared resource are as follows: locking and traversing the shared resource, and searching whether the shared resource exists in the node; if the node exists, the traversal is finished, and if the node does not exist, the node is added to the linked list.
The shared resource under the multi-core high concurrency scene is protected by using the lock, although the problem of multi-process synchronization can be avoided, only a single process can access the same resource at the same time, so that the multi-core process is executed serially, and the concurrent execution capacity of the program is reduced. That is, although the shared resource is protected by the lock, the shared resource may not be operated by mistake, but if the shared resource is protected by the lock simply and roughly in different scenes, not only the resource waste is caused, but also the concurrent performance of the program is reduced.
Based on this, the embodiment of the present application provides a shared resource access method, which solves the problem that, due to lock protection on a shared resource, the shared resource can only be accessed by the same process at the same time, and parallel access of a multi-core device to the shared resource is changed into serial access, so that the concurrent performance of a program is greatly reduced.
Referring to fig. 1, fig. 1 is a first access flowchart of a shared resource according to an embodiment of the present application; the shared resource access method provided by the embodiment of the application aims to solve the problem of reduced concurrent performance of a program caused by adding nodes to shared resources; the shared resource access method can be realized by the following steps:
step S100: and acquiring a linked list of resources to be accessed.
In the step S100, a linked list of resources to be accessed is obtained; it should be noted that the linked list is a non-continuous and non-sequential storage structure on the physical storage unit, the logical sequence of the data elements is realized by the pointer address of the linked list, and is composed of a series of nodes (addresses), and the nodes can be dynamically generated.
Step S101: and traversing the linked list and judging whether the target node can be found in the linked list.
Step S102: and if the target node cannot be found in the linked list, locking the linked list to obtain a locked linked list.
In the above steps S101-S102, traversing the linked list of the resource to be accessed, and determining whether the target node can be found in the linked list; if the target node cannot be found in the linked list, the linked list needs to be locked, that is, the shared resource needs to be locked, so as to obtain the locked shared resource.
Step S103: and traversing the locking linked list, and judging whether the target node can be found in the locking linked list.
Step S104: and if the target node can be found in the locking linked list, accessing the target node.
In the above steps S103-S104, after the linked list of the resource to be accessed is locked; further, traversing the locked linked list again, and judging whether the target node can be found in the locked linked list again; if the target node can be found in the locked linked list, the target node can be directly accessed.
It should be noted that, in general, if a node is to be added to a shared resource, it is first required to determine whether the node exists on the shared resource, and then the node is often confirmed by traversing the shared resource; at this time, the shared resources do not need to be modified, and in most cases, nodes exist, and the conclusion can be obtained only by one common traversal (lock-free traversal), so that in most cases, the resource consumption of one locking can be saved. In the process of lock-free traversal, the multi-core program can be executed concurrently; therefore, the parallel access is not caused to become the serial access.
As can be seen from fig. 1, in the shared resource access method provided in the embodiment of the present application, to access a target resource, a linked list to be accessed is first obtained, and after obtaining the linked list of the resource to be accessed; traversing the linked list, and judging whether the target node can be found in the linked list or not; if the target node cannot be found, locking the shared resource, and traversing the linked list again after locking; if the target node is found, the target resource can be accessed. Therefore, the shared resource access method provided by the embodiment of the application can avoid resource consumption caused by locking to a certain extent, and can improve the concurrency performance of the program.
Referring to fig. 2, fig. 2 is a flowchart of searching for a target node according to an embodiment of the present application; in an optional implementation manner of the embodiment of the present application, traversing the linked list, and determining whether the target node can be found in the linked list can be implemented by the following steps:
step S200: and acquiring a target node element of the target node.
In the step S200, a target node element of the target node is obtained; as will be appreciated by those skilled in the art, each node in the linked list has a node element to which the node corresponds, with different nodes corresponding to different node elements.
Step S201: starting from the initial node of the linked list, searching the target node according to the node element of the target node to the last node of the linked list.
In the above step S201, the specified data element is searched in the linked list, and the most common method is: and traversing all the nodes in sequence from the initial node until the node for storing the target element is found. If the last node is not found, it indicates that the element is not stored in the linked list.
Step S203: and judging whether a target node with the node element consistent with the target node element can be found in the linked list or not.
In step S203, when traversing the nodes in the linked list, the node elements of the target node are compared with the node elements in the linked list, and it is determined whether the target node having the node element that is the same as the target node element can be found in the linked list.
As can be seen from fig. 2, in order to search a target node in a linked list, all nodes in the linked list are traversed from the first node of the linked list by obtaining the node element of the target node, and the node element of each node is compared with the node element of the target node, so as to determine whether the target node can be found from the linked list; therefore, by using the shared resource access method provided by the embodiment of the application, when the linked list is traversed for the first time, the conclusion whether the target node exists in the linked list can be obtained, and the condition that the multi-core program cannot run in parallel due to direct locking traversal cannot be caused.
Please refer to fig. 3, fig. 3 is a schematic diagram illustrating a generation of a locked chain table according to an embodiment of the present application; in an optional implementation manner of the embodiment of the present application, locking generally refers to applying a spin lock or a read-write lock; in which spin
The lock means that when a thread acquires the lock, if the lock is acquired by other threads, the thread 5 waits circularly, and then continuously judges whether the lock can be acquired successfully or not, and the lock cannot be acquired until the lock is acquired
Exiting the loop; the read-write lock is a special spin lock, and divides an accessor for sharing resources into a reader and a writer, wherein the reader only performs read access on the sharing resources, and the writer needs to perform write operation on the sharing resources. The method for locking the linked list to obtain the locked linked list can be realized by the following steps:
step S300: and acquiring an updating instruction of the linked list, and locking the linked list according to the updating instruction.
0 step S301: the linked list is updated to obtain a locked linked list.
In the above steps S300-S301, after the first lock-free traversal, no target node is found in the linked list; acquiring an update instruction of the linked list, and locking the linked list according to the update instruction;
the locking operation may be a spin lock or a read-write lock. And after the chain table is locked, updating the chain table so as to obtain a locked chain table, thereby realizing the locking of the shared resource.
5 as can be seen from fig. 3, in the embodiment of the present application, the target is not successfully found in the first lock-free traversal
Under the condition of the node, locking operation is carried out on the shared resource; and after the update instruction of the linked list is obtained, locking the linked list according to the update instruction, and updating the linked list after locking, thereby obtaining the locked shared resource. The shared resource serial access caused by locking traversal in the first traversal is avoided, and the concurrent execution capacity of the program can be improved.
In an optional implementation manner, the shared resource access method further includes: if it can be looked up in the linked list
If the target node is found, the address of the target node is obtained; and accessing the target access resource according to the address of the target node.
Therefore, when the target node can be found in the linked list in the first traversal, the address of the target node is obtained, and the target access resource is accessed according to the address of the target node. It should be understood that the processes may be performed concurrently during the first pass; and operation due to need of adding nodes in linked list
The number of the traversal operations is small, and most cases only need to execute the first traversal; therefore, the shared resource access method provided by embodiment 5 of the present application can only cause serial access of shared resources in a few cases,
and the running resources are saved while the problems of multi-process synchronization such as dirty reading, repeated addition, memory treading and the like are avoided.
Referring to fig. 4, fig. 4 is a second flowchart of accessing a shared resource according to an embodiment of the present application;
in an optional implementation manner of the embodiment of the present application, the method for accessing a shared resource further includes:
step S400: and if the target node cannot be found in the locking linked list, creating the target node, and mounting the target node on the linked list by 0.
Step S401: and accessing the target access resource according to the target node.
In the above steps S400-S401, in the shared resource access method provided in the embodiment of the present application, if no lock is traversed for the first time, a target node cannot be found in the linked list; further, chains of shared resources
Locking the table, and traversing the linked list again after locking; if 5 target nodes can not be found in the linked list, nodes need to be created, and the nodes are mounted on the linked list, so that the target resources are accessed.
As can be seen from fig. 4, in the shared resource access method provided in the embodiment of the present application, after the second locking traversal, if the target node still cannot be found from the linked list, a node needs to be created, and
and mounting the created nodes on a linked list, thereby realizing the access to target resources. Therefore, the shared resource access method provided by embodiment 0 of the present application can protect the linked list from being generated under the condition that the linked list needs to be modified
Dirty reading, repeated adding, memory treading and the like of the program.
Referring to fig. 5, fig. 5 is a flow chart of node creation provided in the embodiment of the present application; in an optional implementation manner of the embodiment of the present application, creating a target node, and loading the target node on a linked list includes the following steps:
step S500: and configuring a target storage space for the target node.
Step S501: and creating a target node and acquiring the address of the target node.
Step S502: and inserting the target node into the target storage space according to the address of the target node so as to mount the target node on the linked list.
In the above steps S500 to S502, in order to create a target node, a target storage space needs to be configured for a node to be created first; after the storage space is configured, a node is created, and the address of a target node is obtained; furthermore, the target node is inserted into the target storage space according to the address of the target node, so that the newly created target node is mounted on the linked list.
As can be seen from fig. 5, in order to create a target node and mount the target node on a linked list, a storage space needs to be configured for the target node first, and the target node is inserted into the linked list according to an address of the target node, thereby implementing the creation of the node.
In an optional embodiment, after the target node is inserted into the target storage space according to the address of the target node to mount the target node on the linked list, the method further includes: the linked list is updated to obtain a linked list that includes the target nodes.
Therefore, in the shared resource access method provided by the embodiment of the application, after the target node is created, the target node is inserted into the target storage space according to the address of the target node, and the linked list added with the target node is updated, so that the linked list comprising the target node is obtained; the creation of the node is completed, and the process can smoothly access the target resource.
Turning to FIG. 6, FIG. 6 is a flow chart of a preferred embodiment provided herein; in order to better understand the shared resource access method provided in the embodiment of the present application, a description will be given by taking statistics of source IP data in a packet forwarding process of a multi-core device as an example.
It should be noted that, in this example, the IP address is used as the node characteristic field for statistics, but specific data information is not concerned, and only the source IP linked list established by using the IP address as the node characteristic is described.
The method comprises the following steps:
step S600: and acquiring and analyzing the message to acquire the connected source IP.
Step S601: and traversing the source IP chain table to find whether the source IP node exists on the chain table or not, and if so, ending the traversal without adding a new node.
In the step S600, the source IP linked list is traversed, the traversal is lock-free, whether the source IP node already exists on the linked list is searched, and the traversal is ended without adding a new node if the source IP node already exists.
Step S602: and locking and protecting the linked list, traversing the source IP linked list, ending the traversal if the corresponding node is found, and creating a new node and mounting the new node on the corresponding linked list if the corresponding node is not found.
In step S602, in order to prevent the multi-core from causing synchronization problem in the operation of the chain table at the same time, the chain table is locked and protected, the source IP chain table is traversed, if the corresponding node is found, the traversal is ended, and if the corresponding node is not found, a new node is created and mounted on the corresponding chain table. The host with the same IP can create a plurality of connections, the number of the source IP addresses is less than or equal to the number of the connections, namely, the number of times of creating the nodes is less than or equal to the number of traversal times.
As can be seen from fig. 6, in the embodiment of the present application, through a two-pass traversal mode, it is implemented to quickly determine whether a node already exists before adding the node, so that a problem of a decrease in a concurrent execution capability of a program due to one-pass locking traversal of the present invention is solved, and an access rate of the program to a shared resource and a concurrent processing capability of the program are improved.
Referring to fig. 7, fig. 7 is a schematic block diagram of a shared resource access system according to an embodiment of the present application; the shared resource access system 100 includes: a linked list obtaining module 110, a target node searching module 120, a locking module 130, and a target node accessing module 140.
The linked list obtaining module 110 is configured to obtain a linked list of resources to be accessed; wherein, the linked list comprises a plurality of nodes; the target node searching module 120 is configured to traverse the linked list and determine whether the target node can be searched in the linked list; the target section comprises a node corresponding to the target access resource; the locking module 130 is configured to lock the linked list to obtain a locked linked list when the target node cannot be found in the linked list; the target node searching module 120 is further configured to traverse the locking linked list and determine whether the target node can be searched in the locking linked list; and the target node accessing module 140 is configured to access the target node when the target node is found in the locked linked list.
In an optional embodiment, the step of the target node searching module 120 traversing the linked list and determining whether the target node can be found in the linked list includes: acquiring a target node element of a target node; the target node searching module 120 searches the target node from the initial node of the linked list to the last node of the linked list according to the node element of the target node; the target node searching module 120 determines whether a target node whose node element is consistent with the target node element can be found in the linked list.
In an optional embodiment, the shared resource access system 100 further includes a linked list updating module 150, and the locking module 130 locks the linked list to obtain a locked linked list, including: the locking module 130 obtains an update instruction of the linked list and locks the linked list according to the update instruction; wherein, the lock comprises a read-write lock and a spin lock; the linked list update module 150 updates the linked list to obtain a locked linked list.
In an optional embodiment, if the target node searching module 120 can search for the target node in the linked list, the address of the target node is obtained; the target node access module 140 accesses the target access resource according to the address of the target node.
In an optional embodiment, shared resource access system 100 further includes a node creation module 160; if the target node searching module 120 cannot find the target node in the locked linked list, the node creating module 160 creates the target node and loads the target node on the linked list; and accessing the target access resource according to the target node.
In an alternative embodiment, the node creating module 160 creates the target node and mounting the target node on the linked list includes: node creation module 160 configures a target storage space for the target node; creating a target node and acquiring the address of the target node; the node creation module 160 inserts the target node into the target storage space according to the address of the target node to mount the target node on the linked list.
In an alternative embodiment, the node creation module 160 inserts the target node into the target storage space according to the address of the target node, and after the target node is mounted on the linked list, the linked list update module 150 updates the linked list to obtain the linked list including the target node.
Please refer to fig. 8, fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure. An embodiment of the present application provides an electronic device 300, including: a processor 301 and a memory 302, the memory 302 storing machine readable instructions executable by the processor 301, the machine readable instructions when executed by the processor 301 performing the method as above.
Based on the same inventive concept, embodiments of the present application further provide a computer-readable storage medium, where computer program instructions are stored, and when the computer program instructions are read and executed by a processor, the computer program instructions perform steps in any of the above-mentioned implementation manners.
The computer-readable storage medium may be a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and other various media capable of storing program codes. The storage medium is used for storing a program, and the processor executes the program after receiving an execution instruction.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
In addition, units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
Furthermore, the functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
Alternatively, all or part of the implementation may be in 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 invention 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.).
In this document, 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 phrases "comprising 8230; \8230;" comprises 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims (10)
1. A method for shared resource access, the method comprising:
acquiring a linked list of resources to be accessed; wherein the linked list comprises a plurality of nodes;
traversing the linked list, and judging whether a target node can be found in the linked list or not; the target section comprises a node corresponding to a target access resource;
if the target node cannot be found in the linked list, locking the linked list to obtain a locked linked list;
traversing the locking linked list and judging whether the target node can be found in the locking linked list or not;
and if the target node can be found in the locking linked list, accessing the target node.
2. The method of claim 1, wherein traversing the linked list and determining whether a target node can be found in the linked list comprises:
acquiring a target node element of the target node;
starting from the initial node of the linked list, searching the target node according to the node element of the target node until the last node of the linked list;
and judging whether a target node with a node element consistent with the target node element can be found in the linked list or not.
3. The method of claim 1, wherein locking the linked list to obtain a locked linked list comprises:
acquiring an updating instruction of the linked list, and locking the linked list according to the updating instruction; wherein the lock comprises a read-write lock and a spin lock;
and updating the linked list to obtain the locking linked list.
4. The method of claim 1, further comprising:
if the target node can be found in the linked list, acquiring the address of the target node;
and accessing the target access resource according to the address of the target node.
5. The method of claim 1, further comprising:
if the target node cannot be found in the locking linked list, creating the target node and mounting the target node on the linked list;
and accessing the target access resource according to the target node.
6. The method of claim 5, wherein creating the target node and mounting the target node on the linked list comprises:
configuring a target storage space for the target node;
creating the target node and acquiring the address of the target node;
and inserting the target node into the target storage space according to the address of the target node so as to mount the target node on the linked list.
7. The method of claim 6, wherein after the target node is inserted into the target storage space according to the address of the target node to mount the target node on the linked list, the method further comprises:
updating the linked list to obtain a linked list including the target node.
8. A shared resource access system, the system comprising: the system comprises a linked list acquisition module, a target node searching module, a locking module and a target node access module:
the linked list acquisition module is used for acquiring a linked list of resources to be accessed; wherein the linked list comprises a plurality of nodes;
the target node searching module is used for traversing the linked list and judging whether a target node can be searched in the linked list or not; the target section comprises a node corresponding to a target access resource;
the locking module is used for locking the linked list to obtain a locked linked list when the target node cannot be found in the linked list;
the target node searching module is further configured to traverse the locking linked list and determine whether the target node can be searched in the locking linked list; and
the target node access module is used for accessing the target node when the target node is found in the locking linked list.
9. An electronic device, comprising a memory having stored therein program instructions and a processor that, when executed, performs the steps of the method of any one of claims 1-7.
10. A computer-readable storage medium having computer program instructions stored thereon for execution by a processor to perform the steps of the method of any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211715382.7A CN115858186A (en) | 2022-12-29 | 2022-12-29 | Shared resource access method, system, electronic device and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211715382.7A CN115858186A (en) | 2022-12-29 | 2022-12-29 | Shared resource access method, system, electronic device and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115858186A true CN115858186A (en) | 2023-03-28 |
Family
ID=85656152
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211715382.7A Pending CN115858186A (en) | 2022-12-29 | 2022-12-29 | Shared resource access method, system, electronic device and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115858186A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117055988A (en) * | 2023-07-11 | 2023-11-14 | 荣耀终端有限公司 | Lightweight operating system optimization processing method and electronic equipment |
-
2022
- 2022-12-29 CN CN202211715382.7A patent/CN115858186A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117055988A (en) * | 2023-07-11 | 2023-11-14 | 荣耀终端有限公司 | Lightweight operating system optimization processing method and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US6681391B1 (en) | Method and system for installing software on a computer system | |
CN107832062B (en) | Program updating method and terminal equipment | |
EP3267308B1 (en) | Application loading method and device | |
US7149865B2 (en) | Memory allocation using mask-bit pattern to encode metadata within memory address | |
US20150363195A1 (en) | Software package management | |
CN111694638A (en) | Rule package loading method, rule package executing method and terminal equipment | |
US10073646B2 (en) | Multi-tier data synchronizer based on concurrent linked list | |
CN111984264B (en) | Static library generation method and device | |
US20120011166A1 (en) | Skip list generation | |
EP1788493A1 (en) | Detecting changes in data | |
US8185888B2 (en) | Software execution with minimal impact deployment | |
CN113127430A (en) | Mirror image information processing method and device, computer readable medium and electronic equipment | |
CN115858186A (en) | Shared resource access method, system, electronic device and storage medium | |
US8959309B2 (en) | Skip list generation | |
US8719274B1 (en) | Method, system, and apparatus for providing generic database services within an extensible firmware interface environment | |
CN108694049B (en) | Method and equipment for updating software | |
CN113590144B (en) | Dependency processing method and device | |
CN114443598A (en) | Data writing method and device, computer equipment and storage medium | |
CN113254464B (en) | Data loading method and device | |
CN111209304B (en) | Data processing method, device and system | |
CN113760237A (en) | Compiling address updating method and device, terminal equipment and readable storage medium | |
CN115543399A (en) | Software processing system, software processing method and device | |
CN112100479A (en) | Application access method and device, electronic equipment and storage medium | |
CN118972254B (en) | Network configuration version management method, device and electronic device | |
CN117520267B (en) | A storage method, device, equipment and storage medium for directory index nodes |
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 |