CN108228331B - Resource management method and system - Google Patents

Resource management method and system Download PDF

Info

Publication number
CN108228331B
CN108228331B CN201611128750.2A CN201611128750A CN108228331B CN 108228331 B CN108228331 B CN 108228331B CN 201611128750 A CN201611128750 A CN 201611128750A CN 108228331 B CN108228331 B CN 108228331B
Authority
CN
China
Prior art keywords
resource
association
module
resources
access
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.)
Active
Application number
CN201611128750.2A
Other languages
Chinese (zh)
Other versions
CN108228331A (en
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.)
Shanxi Kehua Yongxing Software Application Service Co ltd
Original Assignee
Wuhan Douyu Network Technology 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201611128750.2A priority Critical patent/CN108228331B/en
Publication of CN108228331A publication Critical patent/CN108228331A/en
Application granted granted Critical
Publication of CN108228331B publication Critical patent/CN108228331B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • 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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Abstract

The invention discloses a resource management method and a system, wherein the method comprises the following steps: setting a first association between a main module and a resource, so that the main module can access the resource and release a memory occupied by the resource based on the first association; setting a second association according to the first association; communicating the second association to at least one slave module, enabling the slave module to access the resource based on the second association. The resource management method and the resource management system provided by the invention solve the technical problems of uncertainty of resource release and incapability of effectively managing resources in the resource method in the prior art, can realize effective management on resources and realize the technical effect of effectively managing the memory.

Description

Resource management method and system
Technical Field
The invention relates to the technical field of computers, in particular to a resource management method and system.
Background
With the development of computer technology, the transmission and utilization of resources are greatly developed, and resources acquired by people are various, wherein the resources comprise video information, audio information or picture information, and how to manage the resources becomes a key problem.
In the method adopted in the prior art, a plurality of modules establish a relationship with a resource, and the modules establishing the relationship with the resource are counted, so that the modules can share the resource through the established relationship, including reading and releasing, when the resource fails, each module performing the relationship with the resource performs the relationship release operation, that is, when the count of the module establishing the relationship with the resource is 0, the memory occupied by the resource is released.
However, in the above method, when releasing the memory occupied by the resource, each module associated with the resource needs to perform the disassociation operation, but the time for performing the disassociation operation by each module is uncertain, and it is also uncertain which module performs the disassociation operation last, which may lead to uncertainty of resource release and may not effectively manage the resource. Therefore, the resource management method in the prior art has limitations.
Disclosure of Invention
The invention provides a resource management method and a resource management system, which are used for solving the technical problems of uncertainty of resource release and incapability of effectively managing resources in a resource method in the prior art.
In a first aspect, an embodiment of the present invention provides a method for managing resources, including: setting a first association between a main module and a resource, so that the main module can access the resource and release a memory occupied by the resource based on the first association; setting a second association according to the first association; communicating the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
Optionally, before the setting the first association between the master module and the resource, the method further includes: acquiring the resource; sending the resource to the master module.
Optionally, the setting a first association between the master module and the resource, so that the master module can access the resource and release the memory occupied by the resource based on the first association, includes: judging whether the resource is invalid or not; if the resource is not accessed, checking whether the resource is accessed; and if the resources are not accessed, releasing the memory occupied by the resources.
Optionally, after the releasing the memory occupied by the resource, the method further includes: releasing the first association.
Optionally, the communicating the second association to at least one slave module to enable the slave module to access the resource based on the second association includes: determining whether the first association is released based on the second association; if not, the resource is accessed.
Based on the same inventive concept, an embodiment of the present invention provides a resource management system, including: the first setting module is used for setting a first association between the main module and the resource, so that the main module can access the resource and release the memory occupied by the resource based on the first association; a second setting module, configured to set a second association according to the first association; a transfer module that transfers the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
Optionally, the system further includes: a first obtaining module, configured to obtain the resource; and the sending module is used for sending the resources to the main module.
Optionally, the first setting module includes: a first judging unit, configured to judge whether the resource is invalid; a checking unit, configured to check whether the resource is accessed if the resource fails; and the releasing unit is used for releasing the memory occupied by the resource if the resource is not accessed.
Optionally, the first setting module further includes: a release unit configured to release the first association.
Optionally, the transfer module includes: a second determination unit configured to determine whether the first association is released according to the second association; an accessing unit, configured to access the resource if the first association is released.
The technical scheme provided by the embodiment of the invention at least has the following technical effects or advantages:
in the technical solution of the embodiment of the present invention, by setting a first association between a master module and a resource, the master module may access the resource or release a memory occupied by the resource based on the first association; and setting a second association according to the first association, and then transmitting the second association to at least one slave module, so that the slave module accesses the resource based on the second association. In the above technical solution, since the master module obtains access and release permissions to the resource through the first association, and the slave module receives the second association, which is transmitted by the master module and is set based on the first association, has access permissions to the resource but does not have permissions to release the resource, in the management of the resource, the management permissions of the master module and the slave module to the resource are defined, the master module and the slave module can both access the resource, and only the master module can release the resource, so that compared with the prior art, the uncertainty of resource management is reduced in the present invention, the resource can be effectively managed, and thus the effective management of the memory is realized.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a diagram illustrating the management of objects by pointers in the prior art;
FIG. 2 is a diagram illustrating management of objects in a pointer manner using pointers according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating object deletion by using a pointer method according to an embodiment of the present invention;
FIG. 4 is a flowchart of a method for managing resources according to an embodiment of the present invention;
fig. 5 is a schematic diagram of a logical structure of a resource management system according to an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a resource management method and a resource management system, solves the technical problems of uncertainty of resource release and incapability of effectively managing resources in a resource method in the prior art, can realize effective management of resources, and realizes the technical effect of effectively managing a memory.
The technical scheme in the embodiment of the invention has the following general idea: firstly, setting a first association between a master module and a resource, so that the master module can access the resource or release the first resource occupied by the resource based on the first association; and setting a second association according to the first association, and then transmitting the second association to at least one slave module, so that the slave module accesses the resource based on the second association.
In the method, since the master module obtains the access and release authority to the resource through the first association, the slave module has the access authority to the resource but does not have the authority to release the resource by receiving the second association which is transmitted by the master module and is based on the first association, in the management of the resources, the management authority of the master module and the slave module to the resources is defined, the master module and the slave module can access the resources, only the master module can release the resources, compared with the prior art that all modules have access and release permissions on resources and all modules need to release resources to release the memory of the resources, the management permissions of all modules on the resources are determined, the uncertainty of resource release is reduced, the resources can be effectively managed, and therefore the memory can be effectively managed.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
The present embodiment provides a method for managing resources, please refer to fig. 4, where the method includes:
s101: setting a first association between a main module and a resource, so that the main module can access the resource and release a memory occupied by the resource based on the first association;
s102: setting a second association according to the first association;
s103: communicating the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
The following describes in detail, with reference to fig. 4, specific implementation steps of a resource management method according to an embodiment of the present invention:
first, step S101 is executed to set a first association between a master module and a resource, so that the master module can access the resource and release a memory occupied by the resource based on the first association.
In the embodiment of the present invention, the resources may be audio resources, video resources, picture resources, text resources, and the like, where the first association refers to a corresponding relationship between the main module and the resources, so that the main module may access and release the resources through the first association, where the access to the resources indicates reading of the resources, and the release of the resources indicates deletion of the resources.
Then, step S102 is executed to set a second association according to the first association.
In the embodiment of the invention, on the basis of the first association, a second association is set, namely, another corresponding relation is set and is related to the first association.
Then, step S103 is executed to transfer the second association to at least one slave module, so that the slave module accesses the resource based on the second association.
In the embodiment of the present invention, the established second association may be transferred to a plurality of slave modules, so that the plurality of slave modules access the resource based on the second association, and the access of the respective slave modules to the resource is not affected by each other, and based on the second association, the slave modules obtain only the access right of the resource.
In order to more clearly illustrate a method of resource management of the present invention, a specific implementation is described below with reference to fig. 1 to 3.
The management of resources in the prior art is generally implemented by using a Pointer (Pointer), which is an object in a programming language and uses an address, and the value of the Pointer directly points to a value at another place in a storage memory, as shown in fig. 1.
On the left side of fig. 1 is a simple c + + code, which uses the new key to create a block of integer variable memory space, initializes the memory space to a value of 10, and then points to the address using the integer pointer p. To the right of the memory allocation diagram, it can be seen that pointer p points to an address of 0x00281e08, which is a shaping variable of 10. In c + +, we generally create an object as above and then manipulate the object through object pointers. Thus, in the management of resources, a pointer can be created to the resource, and the module can manage the resource through the pointer.
In order to enable a plurality of modules to share resources, the resources can be shared by adopting an intelligent pointer technology based on pointers, the intelligent pointer technology allows a plurality of pointers to point to the same object, associates a counter with the pointed object, and tracks how many pointers share the same object, so that the sharing of the resources by the plurality of modules can be realized, but when the resources are expired or invalid and the memory occupied by the resources needs to be released, each module executes a release operation, when one module executes the release operation, the reference count is reduced by 1 until the last module executes the release operation, and when the reference count is 0 and the module associated with the resources is 0, the resources can be released, so that the memory occupied by the resources can be released, but the time for executing the release operation by each module is uncertain, which can lead to uncertainty of resource management release, thereby generating an exception, resulting in failure to effectively manage resources.
Thus, the present invention manages objects by using pointers, specifically referring to fig. 2 and 3, in the manner of pointers, i.e., addresses, of pointers, which are special pointers and indicate that the pointer points to a pointer, i.e., an address.
From fig. 2 we can see that addressing pointer p, assigning the pointer pp to the address of pointer p, requires two levels of indirect addressing if we need to access a shaping variable with a value of 10 through pp. When another module or object needs to use the shaping variable, we pass the pp, here assigning pp _ copy to pp, and see that pp _ copy also points to the address of p. That is, access to the reshaped variable is obtained by sharing p, rather than sharing the address of the reshaped variable directly.
As shown in fig. 3, if the memory space of the integer variable of the new application needs to be released, the address space pointed to by P needs to be assigned to 0, and it can be seen that the value of the address space pointed to by pp _ copy is 0; when the address space pointed to by P is assigned to 0, the situation can be obtained through pp or pp _ copy, that is, after the memory space is released, all modules and objects using the shared object can know that it is only necessary to determine whether pp is 0 or not. Therefore, the shared object is managed through the pointer of the pointer, the object applied by the new operation can be deleted actively, and the module sharing the object can know whether the object is released or not, so that the problem of uncertainty of release of the intelligent pointer is solved.
In a specific implementation process, the method can be implemented by a c + + template, for example, the following code creates a shared _ r _ pp template which can implement resource management, and the implementation of the shared _ r _ pp template is different from that of a general intelligent pointer in the setting of member variables and an own release function. In the template, the member variable comprises a pointer _ ptr and a pointer _ pptr of the pointer, the role of the pointer _ ptr is to assign values to the _ pptr, the role of the pointer _ ptr is to distinguish the master-slave relationship, and a release function provides a function for actively releasing the object for a user. Shared _ r _ pp is used to manage shared objects, and new object is needed first and passed to shared _ r _ pp, and the constructor of shared _ r _ pp assigns values to _ ptr and _ pptr. Since the above-mentioned shared _ r _ pp object constructed by using the constructor has no member variable _ ptr nor _ pptr of 0, if the shared _ r _ pp object is constructed by copying the constructor and the assignment operator, the member variable _ ptr of 0, then looking at the release function, if _ ptr is 0, the function will not actually release the managed shared object. Therefore, as can be seen from the above description, only the shared _ r _ pp object constructed by the constructor can release the shared object, and other shared _ r _ pp objects that acquire the usage rights of the shared object by copying the constructor and the assignment operator cannot release the shared object but only have the read rights. The following is the partial implementation code for the shared _ r _ pp object:
Figure BDA0001175221770000071
Figure BDA0001175221770000081
Figure BDA0001175221770000091
optionally, in a resource management method provided in an embodiment of the present invention, before setting the first association between the main module and the resource, the method further includes:
acquiring the resource;
sending the resource to the master module.
In the embodiment of the present invention, the resource may be an audio resource, a video resource, a picture resource, a text resource, and the like, and the resource may be obtained from a network or a local device, which is not limited in the present invention.
Optionally, in a resource management method provided in an embodiment of the present invention, setting a first association between a master module and a resource, so that the master module can access the resource and release a memory occupied by the resource based on the first association, includes:
judging whether the resource is invalid or not;
if the resource is not accessed, checking whether the resource is accessed;
and if the resources are not accessed, releasing the memory occupied by the resources.
Specifically, since the resources are updated quickly in the actual application process, some resources may fail due to time, content, and other factors, and at this time, the resources need to be released, but since a plurality of slave modules can access the resources, if the slave modules access the resources, the master module performs the operation of releasing the resources, which may also cause an exception in resource management, in order to better manage the resources, the master module needs to first determine whether the resources fail when deleting the memory occupied by the resources, and if the resources fail, check whether the resources are accessed, and if the resources are not accessed, then release the memory of the resources.
In a specific implementation process, reading and releasing of resources can be achieved through setting of a read-write lock, the read-write lock is actually a special spin lock, management of shared resources is divided into readers and writers, the readers only read the shared resources, and the writers can write the shared resources. Such a lock can improve concurrency relative to a spin lock, because in a multiprocessor system it allows multiple readers to access a shared resource at the same time. Writers are exclusive, and a read-write lock can only have one writer or a plurality of readers at the same time, but cannot have both readers and writers at the same time. If the read-write lock does not currently have a reader, nor a writer, then the writer can immediately acquire the read-write lock, otherwise it must spin there until there is no writer or reader. If the read-write lock has no writer, then the reader can immediately acquire the read-write lock, otherwise the reader must spin there until the writer releases the read-write lock. In the invention, the master module has the right of reading and writing operations on the resources, while the slave module only has the right of reading on the resources, and the master module and the slave module can manage the resources through the read-write lock.
It is also necessary to introduce the concept of Multithreading, Multithreading (Multithreading), which refers to a technique for implementing concurrent execution of multiple threads from software or hardware. The computer with multithreading capability can execute more than one thread at the same time due to the hardware support, thereby improving the overall processing performance. Systems with this capability include symmetric multiprocessors, multi-core processors, and Chip-level multiprocessing (Chip-level multithreading) or Simultaneous multithreading (Simultaneous multithreading) processors. In a program, these independently running program fragments are called "threads" (Thread), and the concept of programming using them is called "Multithreading". The computer with multithreading capability can execute more than one thread at the same time due to the hardware support, thereby improving the overall processing performance. In multi-threaded applications, data synchronization between different threads and deadlock prevention need to be considered. Deadlocks between threads can be created when two or more threads simultaneously wait for each other to release resources. To prevent deadlock from occurring, thread security needs to be implemented through synchronization. In the invention, the plurality of slave modules are equivalent to a plurality of threads, and through multithread processing, each slave module can access resources through data synchronization and deadlock prevention among different threads.
As can be seen from the above description, in the embodiment of the present invention, the master module has access and release permissions to the resource by establishing the first association between the master module and the resource, the second association is set based on the first association, and the slave module is transferred with the second association, so that the slave module has access permissions to the resource, that is, the master module and the slave module have different management permissions to the resource, so that the management permissions are clear and definite, the master module and the slave module can both access the resource, only the master module can release the video resource, and compared with the prior art, the present invention reduces uncertainty of resource release, and can effectively manage the resource, thereby implementing effective management of the memory.
Optionally, after the releasing the memory occupied by the resource, the method further includes: releasing the first association.
Specifically, the first association is provided in order to release the memory occupied by the resource by the first association, and the first association between the master and the resource becomes meaningless even after the master releases the memory occupied by the resource, and therefore, the first association needs to be released.
Optionally, the communicating the second association to at least one slave module to enable the slave module to access the resource based on the second association includes:
judging whether the first association is released or not according to the second association;
if not, the resource is accessed.
Specifically, since the master module transfers the second association to the slave module and the second association is set based on the first association, the slave module can determine the first association by the second association, and if the first association does not exist, the access to the resource is meaningless, and therefore, when the slave module accesses the resource based on the second association, it can determine whether the first association is released or not by the slave module based on the second association; when the first association is not released, then the resource is accessed.
Based on the same inventive concept, the invention provides another embodiment, which is described in detail in embodiment two.
Example two
The present embodiment provides a resource management system, including:
a first setting module 201, configured to set a first association between a master module and a resource, so that the master module can access the resource and release a memory occupied by the resource based on the first association;
a second setting module 202, configured to set a second association according to the first association;
a transfer module 203 for transferring the second association to at least one slave module to enable the slave module to access the resource based on the second association.
Optionally, the system further includes:
a first obtaining module, configured to obtain the resource;
and the sending module is used for sending the resources to the main module.
Optionally, the first setting module includes:
a first judging unit, configured to judge whether the resource is invalid;
a checking unit, configured to check whether the resource is accessed if the resource fails;
and the releasing unit is used for releasing the memory occupied by the resource if the resource is not accessed.
Optionally, the first setting module further includes:
a release unit configured to release the first association.
Optionally, the transfer module includes:
a second determination unit configured to determine whether the first association is released according to the second association;
an accessing unit, configured to access the resource if the first association is released.
EXAMPLE III
In this embodiment, a video resource is taken as an example to describe in detail a resource management method and system of the present invention.
Firstly, a video stream is obtained from a network, after the video stream is subjected to decoding processing, the video stream needs to be processed for a plurality of modules (each processing module is in a different thread and is also in a different thread from video decoding), for example, rendering, watermarking, writing a file, writing the file into a shared memory for use by other processes, and the like. Firstly, regarding the acquisition of the video stream, acquiring a stream address, regarding the stream address, acquiring the stream address by inquiring a website server, then opening the stream address by using an avformat _ open _ input function of an FFmpeg library, and acquiring audio/video stream data by using an av _ read _ frame function. Ffmpeg (fast forwarding moving Picture Experts group) is an open source free cross-platform video and audio streaming solution that provides a complete solution for recording, converting, and streaming audio and video. And includes very advanced audio/video codec library libavcodec, which in the embodiment of the present invention needs to use FFMPEG to acquire and decode the video stream. Only video data is needed, so when the stream is analyzed, the id of the stream of the video and audio is needed to be obtained, then when the frame is read, the streamid of the frame is used for comparison and judgment, if the frame is an audio frame, pass is directly carried out, and the obtained video data packet is directly transmitted to a decoding module.
The first setting module is used for setting a first association between the main module and the resource, so that the main module can access the resource and release the memory occupied by the resource based on the first association;
specifically, the delivered video data packet is decoded using avcodec _ decode _ video2, and a new stVideoFrame object stores the video frame, and then the stVideoFrame object is managed by delivering an stVideoFrame pointer to create a shared _ r _ pp object using a constructor, wherein the first association can be realized by a pointer _ ptr since the shared _ r _ pp object is created by the stVideoFrame pointer, and the value of _ ptr is not 0 since the shared _ r _ pp object is created by the constructor. And a list container is adopted to store all shared _ r _ pp objects, so that the management of all the stVideoFrame objects coming out of the new video is facilitated. In addition, the decoding module can create a timer for regularly traversing the shared _ r _ pp objects stored in the list container, and can recover the expired video data, and can call the shared _ r _ pp, wherein the release function is used for recovering, and the specific steps are as follows: decomposing the video information into video frames; acquiring a timestamp of the video frame; judging whether the timestamp exceeds preset time or not; if yes, releasing the memory occupied by the video frame until the sum of the released memories of the second resources is the memory occupied by the video information; specifically, pts can be bound with the local time according to the stVideoFrame, and a preset time can be set by a person skilled in the art according to the actual situation, for example, 2 seconds, 3 seconds, and the like, and the video frame is released when the preset time is exceeded until all the constituent video frames of the video are released, and after the release is completed. The stVideoFrame structure is defined as follows:
Figure BDA0001175221770000131
Figure BDA0001175221770000141
as can be seen from the above, the creation and destruction of the stVideoFrame object for managing video data are both performed in the decoding module, and the decoding module applies for and releases complete control over the stVideoFrame object (i.e., video resource), so that a better memory management manner such as a memory pool can be used, and the size of a memory used by a program can also be controlled.
A second setting module, configured to set a second association according to the first association; a transfer module that transfers the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
Specifically, the decoding module transfers the decoded video data to the rendering module through the shared _ r _ pp object respectively (since the shared _ r _ pp object is transferred here, the shared _ r _ pp object obtained by the rendering module is created by copying the constructor, so the _ ptr value of the object is 0), the rendering module also uses the list container to store the received video shared _ r _ pp object, and the video shared _ r _ pp object in the list container needs to be sorted according to stVideoFrame:: pts. The video data used by the rendering module or the video data stored by the stVideoFrame object from the encoding module new is one frame of video, and the encoding module and the rendering module use one video data, so that the memory copy of the video frame data is not performed, the use of the memory is reduced, and the performance is improved.
The rendering module decides when to render the video frame according to stVideoFrame:: pts, which is the timestamp of the video frame. When a frame of video is rendered, acquiring the video shared _ r _ pp object from the list container, and checking whether the returned value is 0 or not by calling a- > operator of the shared _ r _ pp, wherein if the returned value is 0, the video frame stored in the shared _ r _ pp object is destroyed, the frame is skipped to be rendered, and if the returned value is not 0, the video frame needs to be rendered. It can be seen that the rendering module may also know when the decoding module destroys the video shared _ r _ pp object. In addition, the rendering module calls the shared _ r _ pp, namely the release function can not destroy the video frame, and the rendering module only has the right to read the video shared _ r _ pp object.
Various changes and specific examples of the resource management method in the foregoing embodiments are also applicable to the system in this embodiment, and those skilled in the art can clearly know the implementation method of the resource management system in this embodiment through the foregoing detailed description of the resource management method, so for the brevity of the description, detailed descriptions are not provided here.
The technical scheme provided by the embodiment of the invention at least has the following technical effects or advantages:
in the technical solution of the embodiment of the present invention, by setting a first association between a master module and a resource, the master module may access the resource or release a memory occupied by the resource based on the first association; and setting a second association according to the first association, and then transmitting the second association to at least one slave module, so that the slave module accesses the resource based on the second association. In the above technical solution, since the master module obtains access and release permissions to the resource through the first association, and the slave module receives the second association, which is transmitted by the master module and is set based on the first association, has access permissions to the resource but does not have permissions to release the resource, in the management of the resource, the management permissions of the master module and the slave module to the resource are defined, the master module and the slave module can both access the resource, and only the master module can release the resource, so that compared with the prior art, the uncertainty of resource management is reduced in the present invention, the resource can be effectively managed, and thus the effective management of the memory is realized.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various modifications and variations can be made in the embodiments of the present invention without departing from the spirit or scope of the embodiments of the invention. Thus, if such modifications and variations of the embodiments of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to encompass such modifications and variations.

Claims (10)

1. A method for resource management, comprising:
setting a first association between a main module and a resource, so that the main module can access the resource and release the memory occupied by the resource based on the first association, wherein the first association is obtained by creating a shared _ r _ pp object through a constructor, member variables of the shared _ r _ pp object comprise a pointer _ ptr and a pointer _ pptr of the pointer, and the shared _ r _ pp object constructed by the constructor has a value of neither the _ ptr nor the _ pptr being 0;
setting a second association according to the first association, wherein the second association is obtained by copying a constructor, and the value of the _ ptr is 0;
communicating the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
2. The method of claim 1, prior to said setting up the first association of the master module with the resource, further comprising:
acquiring the resource;
sending the resource to the master module.
3. The method of claim 1, wherein setting a first association of a master module with a resource to enable the master module to access the resource and release memory occupied by the resource based on the first association comprises:
judging whether the resource is invalid or not;
if the resource is not accessed, checking whether the resource is accessed;
and if the resources are not accessed, releasing the memory occupied by the resources.
4. The method of claim 3, wherein after releasing the memory occupied by the resources, further comprising:
releasing the first association.
5. The method of claim 1, wherein said communicating the second association to at least one slave module to enable the slave module to access the resource based on the second association comprises:
judging whether the first association is released or not according to the second association;
if not, the resource is accessed.
6. A resource management system, comprising:
a first setting module, configured to set a first association between a master module and a resource, so that the master module can access the resource and release a memory occupied by the resource based on the first association, where the first association is obtained by creating a shared _ r _ pp object through a constructor, where member variables of the shared _ r _ pp object include a pointer _ ptr and a pointer _ pptr of the pointer, and the shared _ r _ pp object constructed by using the constructor has values of _ ptr and _ pptr that are not 0;
a second setting module, configured to set a second association according to the first association, where the second association is obtained by copying a constructor, and a shared _ r _ pp object constructed by copying the constructor has a value of 0;
a transfer module that transfers the second association to at least one slave module, enabling the slave module to access the resource based on the second association.
7. The system of claim 6, further comprising:
a first obtaining module, configured to obtain the resource;
and the sending module is used for sending the resources to the main module.
8. The system of claim 6, wherein the first setup module comprises:
a first judging unit, configured to judge whether the resource is invalid;
a checking unit, configured to check whether the resource is accessed if the resource fails;
and the releasing unit is used for releasing the memory occupied by the resource if the resource is not accessed.
9. The system of claim 8, wherein the first setup module further comprises:
a release unit configured to release the first association.
10. The system of claim 6, wherein the transfer module comprises:
a second determination unit configured to determine whether the first association is released according to the second association;
an accessing unit, configured to access the resource when the first association is not released.
CN201611128750.2A 2016-12-09 2016-12-09 Resource management method and system Active CN108228331B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611128750.2A CN108228331B (en) 2016-12-09 2016-12-09 Resource management method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611128750.2A CN108228331B (en) 2016-12-09 2016-12-09 Resource management method and system

Publications (2)

Publication Number Publication Date
CN108228331A CN108228331A (en) 2018-06-29
CN108228331B true CN108228331B (en) 2021-11-26

Family

ID=62637168

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611128750.2A Active CN108228331B (en) 2016-12-09 2016-12-09 Resource management method and system

Country Status (1)

Country Link
CN (1) CN108228331B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109982132A (en) * 2019-04-23 2019-07-05 姚耀 A kind of double recording systems of audio and video remote
CN110730364B (en) * 2019-10-14 2021-08-31 广州微算互联信息技术有限公司 Cloud mobile phone data transmission method and device and storage medium
CN113127140A (en) * 2019-12-31 2021-07-16 阿里巴巴集团控股有限公司 Resource management method, device and system
CN114531602B (en) * 2020-11-23 2024-02-23 中国移动通信集团安徽有限公司 Video live broadcast performance optimization method and device based on dynamic resource release

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101046755A (en) * 2006-03-28 2007-10-03 郭明南 System and method of computer automatic memory management
CN105302580A (en) * 2015-11-28 2016-02-03 武汉斗鱼网络科技有限公司 Method and system for rapidly acquiring game graphics through GPU (Graphics Processing Unit) texture sharing
CN106231489A (en) * 2016-07-25 2016-12-14 深圳市米尔声学科技发展有限公司 The treating method and apparatus of audio frequency

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101046755A (en) * 2006-03-28 2007-10-03 郭明南 System and method of computer automatic memory management
CN105302580A (en) * 2015-11-28 2016-02-03 武汉斗鱼网络科技有限公司 Method and system for rapidly acquiring game graphics through GPU (Graphics Processing Unit) texture sharing
CN106231489A (en) * 2016-07-25 2016-12-14 深圳市米尔声学科技发展有限公司 The treating method and apparatus of audio frequency

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
c++中资源泄露处理方法的研究与实现;李文 等;《计算机安全》;20070831;第63-67页 *
使用二级指针在多线程进行刷选操作;weixin_30648587;《https://blog.csdn.net/weixin_30648587/article/details/98012721》;20141124;第1-2页 *

Also Published As

Publication number Publication date
CN108228331A (en) 2018-06-29

Similar Documents

Publication Publication Date Title
CN108228331B (en) Resource management method and system
EP2985702B1 (en) Data processing method and device, and computer system
LiKamWa et al. Starfish: Efficient concurrency support for computer vision applications
DE112006002237B4 (en) Method for self-initiating synchronization in a computer system
US6622155B1 (en) Distributed monitor concurrency control
US20140173614A1 (en) Sending tasks between virtual machines based on expiration times
US10929201B2 (en) Method and system for implementing generation locks
US20110138135A1 (en) Fast and Efficient Reacquisition of Locks for Transactional Memory Systems
US20080276256A1 (en) Method and System for Speeding Up Mutual Exclusion
US8645963B2 (en) Clustering threads based on contention patterns
US6016490A (en) Database management system
CN106844048B (en) Distributed memory sharing method and system based on hardware characteristics
US20130138886A1 (en) Scheduler, multi-core processor system, and scheduling method
US11436048B2 (en) Method of managing task dependencies at runtime in a parallel computing system of a hardware processing system and a hardware acceleration processor
US20150254113A1 (en) Lock Spin Wait Operation for Multi-Threaded Applications in a Multi-Core Computing Environment
US9213560B2 (en) Affinity of virtual processor dispatching
US20210200668A1 (en) Reserved memory in memory management system
US8666958B2 (en) Approaches to reducing lock communications in a shared disk database
US20180260255A1 (en) Lock-free reference counting
US20210318985A1 (en) Leader election with lifetime term
US6363410B1 (en) Method and system for threaded resource allocation and reclamation
WO2016182899A1 (en) Thread safe lock-free concurrent write operations for use with multi-threaded in-line logging
US20140082624A1 (en) Execution control method and multi-processor system
US20190095475A1 (en) Atomic Updates of Versioned Data Structures
CN116225728B (en) Task execution method and device based on coroutine, storage medium and electronic equipment

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
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20240325

Address after: Room 8009-1, Block B, Dingchen Times Business Building, No. 5 Development Road, Xuefu Industrial Park, Shanxi Transformation and Comprehensive Reform Demonstration Zone, Taiyuan City, Shanxi Province, 030000

Patentee after: Shanxi Kehua Yongxing Software Application Service Co.,Ltd.

Country or region after: China

Address before: 430000 East Lake Development Zone, Wuhan City, Hubei Province, No. 1 Software Park East Road 4.1 Phase B1 Building 11 Building

Patentee before: WUHAN DOUYU NETWORK TECHNOLOGY Co.,Ltd.

Country or region before: China