[go: up one dir, main page]

CN112596877A - Global variable using method, device, system and computer readable storage medium - Google Patents

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

Info

Publication number
CN112596877A
CN112596877A CN202011515034.6A CN202011515034A CN112596877A CN 112596877 A CN112596877 A CN 112596877A CN 202011515034 A CN202011515034 A CN 202011515034A CN 112596877 A CN112596877 A CN 112596877A
Authority
CN
China
Prior art keywords
global variable
global
thread
timestamp
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011515034.6A
Other languages
Chinese (zh)
Inventor
李宏强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen TCL New Technology Co Ltd
Original Assignee
Shenzhen TCL New 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 Shenzhen TCL New Technology Co Ltd filed Critical Shenzhen TCL New Technology Co Ltd
Priority to CN202011515034.6A priority Critical patent/CN112596877A/en
Publication of CN112596877A publication Critical patent/CN112596877A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请公开了一种全局变量的使用方法、装置、系统以及计算机可读存储介质,方法包括:获取第一全局变量的时间戳,所述第一全局变量为待执行程序的全局变量;根据所述时间戳确定所述第一全局变量是否发生改变;当确定所述第一全局变量没有发生改变时,获取读线程处理函数备份的第二全局变量,以使用所述第二全局变量进行功能运算。解决了在多线程读取全局变量,通过线程锁保持线程执行结果的一致性时,存在频繁进行解锁操作,降低线程执行效率的技术问题,提高了线程的执行效率。

Figure 202011515034

The present application discloses a method, device, system and computer-readable storage medium for using a global variable. The method includes: obtaining a timestamp of a first global variable, where the first global variable is a global variable of a program to be executed; The timestamp determines whether the first global variable has changed; when it is determined that the first global variable has not changed, obtain the second global variable backed up by the read thread processing function to use the second global variable to perform functional operations . The technical problem of frequent unlocking operations and reducing thread execution efficiency when multi-threading reads global variables and maintaining the consistency of thread execution results through thread locks is solved, and the execution efficiency of threads is improved.

Figure 202011515034

Description

Global variable using method, device, system and computer readable storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a system, and a computer-readable storage medium for using a global variable.
Background
In a computer system, it is usually necessary to read and write a global variable across threads, which can ensure the correctness of the running result of each thread by using a thread lock. After the global variable is locked by using a thread lock mode, only one thread can access the global variable at the same time, and other threads can only wait. When a thread reads a global variable very frequently and performs a calculation of a business function, the thread that reads and writes the global variable is dragged. Moreover, reading global variables frequently requires performing a lock operation each time, which may result in significant performance degradation of the read thread.
Disclosure of Invention
The embodiment of the application provides a method, a device and a system for using a global variable and a computer readable storage medium, and aims to solve the technical problems that when the global variable is read in multiple threads and the consistency of thread execution results is kept through a thread lock, unlocking operation is frequently performed and thread execution efficiency is reduced.
To achieve the above object, an aspect of the present application provides a method for using a global variable, including:
acquiring a timestamp of a first global variable, wherein the first global variable is a global variable of a program to be executed;
determining whether the first global variable is changed according to the timestamp;
and when the first global variable is determined not to be changed, acquiring a second global variable backed up by the read thread processing function so as to perform functional operation by using the second global variable.
Optionally, the step of determining whether the first global variable is changed according to the timestamp includes:
comparing the timestamp of the first global variable with the timestamp of the second global variable stored in the read thread;
and when the comparison is consistent, confirming that the first global variable is not changed.
Optionally, after the step of determining whether the first global variable is changed according to the timestamp, the method includes:
and when the first global variable is determined to be changed, assigning the first global variable to the read thread processing function so as to use the first global variable to perform the functional operation.
Optionally, before the step of assigning the first global variable to the read thread processing function to perform the functional operation by using the first global variable, the method includes:
acquiring the state of a thread lock;
when the state of the thread lock is an unlocking state, acquiring the first global variable in the thread lock;
and assigning the first global variable to the read thread processing function.
Optionally, after the step of obtaining the state of the thread lock, the method includes:
and if the state of the thread lock is an occupied state, applying for writing the lock so as to read the first global variable in the thread lock.
Optionally, after the step of assigning the first global variable to the read thread processing function, the method includes:
and modifying the timestamp of the first global variable into the timestamp of the first global variable backed up by the read thread processing function, and releasing the thread lock.
Optionally, after the step of obtaining a second global variable backed up by the read thread processing function to perform a functional operation using the second global variable, the method further includes:
and displaying the result of the functional operation to a display interface.
In addition, to achieve the above object, another aspect of the present application further provides an apparatus for using a global variable, including:
the system comprises a first acquisition module, a second acquisition module and a control module, wherein the first acquisition module is used for acquiring a timestamp of a first global variable, and the first global variable is a global variable of a program to be executed;
a determining module, configured to determine whether the first global variable is changed according to the timestamp;
and the second acquisition module is used for acquiring a second global variable backed up by the read thread processing function when the first global variable is determined not to be changed so as to perform functional operation by using the second global variable.
In addition, in order to achieve the above object, in another aspect, the present application further provides a system for using a global variable, where the system for using a global variable includes a processor, a memory, and a program for using a global variable stored in the memory and executable on the processor, and the program for using a global variable, when executed by the processor, implements the steps of the method for using a global variable as described above.
In addition, to achieve the above object, another aspect of the present application further provides a computer-readable storage medium, on which a global variable using program is stored, and when the global variable using program is executed by a processor, the method for using the global variable as described above is implemented.
In this embodiment, when a thread acquires a first global variable of a program to be executed, a timestamp of the first global variable is acquired first, and when it is determined that the timestamp of the first global variable does not change, it is determined that the first global variable does not change, a second global variable stored in a thread-reading processing function is directly acquired, so as to perform functional operation using the second global variable. The unlocking operation does not need to be frequently executed under the condition that the global variable is not changed, and the running efficiency of the thread is improved.
Drawings
Fig. 1 is a schematic terminal structure diagram of a hardware operating environment according to an embodiment of the present application;
FIG. 2 is a schematic flow chart diagram illustrating an embodiment of a method for using global variables according to the present application;
FIG. 3 is a schematic diagram of a real-time flow of a method for using global variables according to the present application;
fig. 4 is a functional module diagram of a method for using global variables according to the present application.
The implementation, functional features and advantages of the objectives of the present application will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The main solution of the embodiment of the application is as follows: acquiring a timestamp of a first global variable, wherein the first global variable is a global variable of a program to be executed; determining whether the first global variable is changed according to the timestamp; and when the first global variable is determined not to be changed, acquiring a second global variable backed up by the read thread processing function so as to perform functional operation by using the second global variable.
In the prior art, in the process of using global variables by multiple threads, it often happens that the global variables are changed due to the end of execution of one thread, but another thread continues to use the unchanged global variables, so that the final result is wrong. In order to solve the problem, a thread lock is usually added to the global variable to ensure that only one thread can perform read-write operation on the global variable at the same time, and only after the current thread finishes using the global variable, the thread lock is released and the next thread can continue to use the global variable. Namely, the synchronization of different threads for acquiring the global variable is ensured in a thread lock mode. But the way of using thread locks may have the problem that each time a thread needs to acquire a global variable by unlocking. If there are multiple threads in a program, each thread needs to perform wait and unlock operations one by one, which will undoubtedly slow down the execution efficiency of the threads. In the method, the timestamp is added to the global variable, when the timestamp is not changed, the representative global variable is not changed, the thread directly reads the backup global variable in the thread reading processing function, operations such as unlocking and lock releasing are not needed to be executed, the step of acquiring the global variable by the thread is simplified, and the overall execution efficiency of the thread is improved.
As shown in fig. 1, fig. 1 is a schematic terminal structure diagram of a hardware operating environment according to an embodiment of the present application.
As shown in fig. 1, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Optionally, the terminal may further include a camera, a Radio Frequency (RF) circuit, a sensor, a remote controller, an audio circuit, a WiFi module, a detector, and the like. Of course, the terminal may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer and a temperature sensor, which are not described herein again.
Those skilled in the art will appreciate that the terminal structure shown in fig. 1 does not constitute a limitation of the terminal device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and a control program of the home appliance.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call the control program of the home appliance stored in the memory 1005 and perform the following operations:
acquiring a timestamp of a first global variable, wherein the first global variable is a global variable of a program to be executed;
determining whether the first global variable is changed according to the timestamp;
and when the first global variable is determined not to be changed, acquiring a second global variable backed up by the read thread processing function so as to perform functional operation by using the second global variable.
Referring to fig. 2, fig. 2 is a schematic flowchart of an embodiment of a method for using global variables according to the present application.
While the embodiments of the present application provide an embodiment of a method for using global variables, it should be noted that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in an order different from that here.
The use method of the global variable comprises the following steps:
step S10, acquiring a timestamp of a first global variable, wherein the first global variable is a global variable of a program to be executed;
the timestamp is the time when the global variable changes, the read thread records the time when the global variable changes, and the timestamp can be marked by using a system tick or a universal coordinated time (UTC) method, so that the repetition is avoided, and the thread is prevented from using an incorrect global variable to perform functional operation. In this embodiment, a system tick is taken as an example for explanation, a system tick execution statement is added in the programming process, and when a global variable changes, a timestamp of the change of the global variable is acquired through the system tick execution statement. Wherein the timestamp may be converted to a date format, which may be 2020-04-0404: 04:04, or 2020/04/04/04/04/04. In this embodiment, the acquired time stamp is converted into a date format by adding the time stamp to the thread, so that the change of the time stamp can be more intuitively understood.
When the thread reads a first global variable of a program to be executed, the thread firstly acquires a time stamp of the first global variable. The method for acquiring the timestamp of the first global variable may be acquired by adding a corresponding method to the thread. In this embodiment, there are four methods for obtaining the timestamp of the first global variable, which are respectively: by Date, by currentTimeMillis method in the System class, by Calendar class, and by Date class.
In the application, the global variable is an array-class variable, and the array-class global variable cannot be released by the thread, so that the situation of calculation errors caused by using historical data when the thread processing function is read to back up the global variable is avoided. When the callback processing function uses the global variable, whether the obtained global variable is historical data or not can be identified through handles or other information, if yes, the currently used global variable is discarded, the operation of obtaining the global variable for assignment is executed, and errors in logic functions caused by using the historical data are avoided.
Step S20, determining whether the first global variable is changed according to the timestamp;
in the present application, the thread determines whether the first global variable has been modified by the timestamp of the first global variable. For example, when the thread reads that the date format converted from the timestamp of the first global variable is 2020-04-0404: 06:07, the thread B is obtained to modify the first global variable in the program to be executed every 2S, the current system time is obtained, the current system time is compared with the time of the obtained first global variable, if the current system time is 2020-04-0404: 06:10, the current system time is calculated to perform difference operation with the time corresponding to the date format of the obtained timestamp, the difference value is 3S and is greater than the period 2S in which the thread B has modified the global variable, and the change of the global variable in the program to be executed is determined. It is understood that there are other methods for determining the change of the global variable by the timestamp, and the method is not limited to the scheme listed in the embodiment.
And step S30, when it is determined that the first global variable has not changed, acquiring a second global variable backed up by the read thread processing function, so as to perform functional operation using the second global variable.
The second global variable is stored in the read thread, and when the timestamp of the second global variable is equal to that of the first global variable, the second global variable is equal to the first global variable; when its timestamp is not equal to that of the first global variable, then the second global variable is not equal to the first global variable.
The functional operation is an operation performed by substituting the first global variable into the execution method after the thread acquires the first global variable. For example, addition, subtraction, multiplication, and division operations.
After the step of obtaining the second global variable backed up by the read thread processing function to perform the functional operation by using the second global variable, the method further includes:
and displaying the result of the functional operation to a display interface.
After the functional operation is executed, in the application, the result of the functional operation is displayed to a display interface, so that a user can know the result of the functional operation performed after the thread assigns the global variable.
And when the thread determines that the global variable changes, executing a step of reading a first global variable in the running program, assigning the read first global variable to a read thread processing function, realizing functional operation by using the first global variable, and updating a second global variable stored in the read thread processing function.
It is understood that multiple threads performing different operations may be started during the running of the program, and the threads may be executed simultaneously or separately (thread a is executed before thread B is executed). When multiple threads are running simultaneously, there may be a delay. For example, when the thread a writes a first global variable of a program to be executed, the thread B reads the first global variable, the period required for the thread a to write the global variable is long, there is a change in the value of the first global variable caused in the process of modifying the first global variable by the thread a, at this time, the system tick in the thread records the modification time of the first global variable, because the modification of the global variable by the thread a takes a long period, if the thread B reads the first global variable in the process of modifying the global variable by the thread a, and performs the functional operation using the first global variable, since the thread a has modified the first global variable, but the thread B still uses the first global variable before the thread a does not perform the modification operation to perform the operation, the operation result obtained when the second global variable backed up in the read thread is assigned to the thread is an error. The problem is usually solved by adopting a thread lock mode, namely in the process that the thread A acquires the first global variable for assignment, the first global variable is locked and can only be assigned by the thread A, other threads enter a waiting state until the thread A finishes assignment of the first global variable, and the thread lock is released. The synchronization of the calculation results can be ensured by locking the global variables. However, when there are a plurality of threads in the program, the waiting and unlocking operations need to be executed continuously, and the running speed of the CPU is reduced.
In this embodiment, when a thread acquires a first global variable in a program to be executed, a timestamp of the first global variable is acquired first, and when it is determined that the timestamp of the first global variable does not change, it is determined that the first global variable does not change, a second global variable stored in a thread-reading processing function is directly acquired, so as to perform functional operation using the second global variable. The unlocking operation is not required to be frequently executed under the condition that the first global variable in the program to be executed is not changed, and the processing efficiency of the thread is improved.
Further, referring to fig. 3, a method for using global variables of the present application is provided.
The present embodiment is different from the previous embodiment in that the step of determining whether the global variable is changed according to the timestamp includes:
step S21, comparing the timestamp of the first global variable with the timestamp of the second global variable stored in the read thread;
and step S22, when the comparison is consistent, confirming that the first global variable is not changed.
In this embodiment, the thread may compare the obtained timestamp of the first global variable with the timestamp of the second global variable backed up in the read thread processing function, and when the comparison result is consistent, it is determined that the first global variable is not changed; and when the comparison result is inconsistent, confirming that the first global variable is changed.
Specifically, the following examples are given in this embodiment: when the thread reads the first global variable, the timestamp of the acquired global first variable is 1603846961000, and when the timestamp stored in the read thread is 1603846961000, the timestamp is determined not to be changed, so that the first global variable is confirmed not to be changed; if it is obtained that the timestamp stored in the read thread is 1603846961001, it is determined that the timestamp has changed, and it is confirmed that the first global variable has changed. Further, in this embodiment, whether the global variable has changed or not can also be intuitively determined by converting the timestamp into a date format, and when the timestamp of the global variable is obtained as 1603846961000, the method is substituted to sequentially obtain the year, month, day, minute, second and millisecond for converting the timestamp into the date format, and finally the converted beijing time is 2020-10-2809: 02:41, so that the change of the timestamp can be more intuitively understood by a time comparison method.
As follows:
Figure BDA0002845123760000081
in this embodiment, the thread may determine whether the timestamp is changed by comparing the read timestamp with the timestamp stored in the read thread, and when the timestamps are not consistent, it is determined that the timestamp of the first global variable has changed; when the timestamps are consistent, it represents that the first global variable has not changed. Whether the time stamp is changed or not is intuitively judged by using a time stamp for comparison.
Based on the previous embodiment, the present application provides another embodiment, which is different from the previous embodiment in that: after the step of determining whether the first global variable has changed according to the timestamp, the method includes:
and step S40, when it is determined that the first global variable has changed, assigning the first global variable to the read thread processing function, so as to perform the functional operation using the first global variable.
In this embodiment, when a thread acquires a first global variable, a timestamp of the first global variable is acquired first, the timestamp of the first global variable is compared with a timestamp stored in a read thread processing function, and when the acquired timestamp of the first global variable is different from a timestamp of a second global variable stored in the read thread processing function, it is determined that the first global variable has changed, and a step of reading the first global variable of a function to be processed needs to be performed to acquire the first global variable, and the first global variable is assigned to the read thread processing function to perform function operation using the first global variable.
In this embodiment, when a thread acquires a first global variable, first, by acquiring a timestamp of the first global variable, whether the first global variable changes is determined by the timestamp, the first global variable of a program to be executed is read only when the first global variable changes, and a second global variable stored in the thread is directly acquired when the timestamp of the first global variable does not change, so that the acquisition of the first global variable of the program to be executed is not required to be uniformly executed, the acquisition step of the first global variable is simplified, and the operating efficiency of the thread is improved.
Before the step of assigning the global variable to the read thread processing function to perform the functional operation by using the global variable, the method includes:
step S01, acquiring the state of the thread lock;
step S02, when the state of the thread lock is an unlocked state, acquiring the first global variable in the thread lock;
in step S03, the first global variable is assigned to the read thread processing function.
When the first global variable is changed, the thread acquires the state of a thread lock of the first global variable of the program to be executed, wherein the state of the thread lock comprises an occupied state and an unlocked state, when the thread lock is in the occupied state, the thread lock represents that other threads currently use the first global variable, and it can be understood that when the thread lock is in the occupied state, the first global variable is already added into the thread lock, and when the thread uses the first global variable, other threads cannot acquire the first global variable through the thread lock at the same time, so that the correctness of an operation result after the thread acquires the first global variable for assignment is ensured; when the thread lock is in the unlocked state, the thread represents that no other thread uses the first global variable currently, and the thread can acquire the first global variable through the unlocking operation. After the thread executes the unlocking operation to obtain the first global variable, the first global variable is assigned to the read thread processing function so that the read thread processing function can obtain the updated first global variable, record the updated first global variable as the second global variable, store the timestamp of the updated first global variable, and use the updated first global variable to perform functional operation.
For example, when the thread a reads the global variable, a timestamp of a first global variable to be read is obtained first, the obtained timestamp is compared with a timestamp of a second global variable read by the thread backup, and when the comparison is inconsistent, it is determined that the thread a needs to perform an unlocking operation to obtain the first global variable. That is, in this embodiment, a timestamp is added before the global variable is determined, so that when the thread acquires the global variable, whether the first global variable with the execution program changes is determined according to a change in the timestamp, and when the thread reads that the first global variable has changed, the thread needs to assign a value to the first global variable in a manner of reading the first global variable, thereby ensuring accuracy of acquiring the first global variable.
After the step of obtaining the state of the thread lock, the method comprises the following steps:
step S04, if the state of the thread lock is an occupied state, applying for a write lock to read a global variable in the thread lock.
When the thread reads that the state of the thread lock is an occupied state, the thread represents that other threads (thread B) are using the first global variable of the program to be executed currently, the state of the thread lock needs to be acquired, when the state of the thread lock is the occupied state, the thread firstly executes the step of applying for unlocking, so that the assignment of the first global variable is completed by the thread B, and the unlocking can be timely carried out to acquire the first global variable when the lock is released.
After the step of assigning the global variable to the read thread processing function, the method includes:
and step S05, modifying the time stamp of the global variable into the time stamp of the read thread processing function backup, and releasing the thread lock.
And after the thread completes the assignment of the global variable, the timestamp of the global variable needs to be modified, the timestamp of the global variable is modified into the timestamp stored in the thread reading processing function, and the thread lock is released for the next thread to obtain.
In this embodiment, after the assignment of the global variable is completed, the timestamp of the global variable is changed to change the timestamp of the global variable into a timestamp in the read thread processing function, so that the timestamp of the global variable is ensured to be consistent with the timestamp in the read thread processing function.
In addition, referring to fig. 3, fig. 3 is a schematic flow chart of the present application.
In the embodiment, the thread 1 performs modification operation on the global variable of the program to be executed, and time stamps on the modification of the global variable. When the thread 2 reads a first global variable of a program to be executed, the acquired timestamp is changed, the step of acquiring the lock is executed, the first global variable is acquired, the global variable is assigned to a backup global variable in the read thread processing function to serve as a second global variable, and when the timestamp of the first global variable is not changed, the second global variable backed up in the read thread is directly acquired, and functional operation is executed. The step of reading the global variable is not required to be uniformly executed by the thread, so that the execution efficiency of the thread is improved.
In addition, referring to fig. 4, fig. 4 is a functional module schematic diagram of the present application. In addition, to achieve the above object, another aspect of the present application further provides an apparatus for using a global variable, including:
a first obtaining module 10, configured to obtain a timestamp of a first global variable, where the first global variable is a global variable of a program to be executed;
a determining module 20, configured to determine whether the first global variable is changed according to the timestamp;
a second obtaining module 30, configured to obtain a second global variable backed up by the read thread processing function when it is determined that the first global variable is not changed, so as to perform functional operation using the second global variable.
In addition, in order to achieve the above object, in another aspect, the present application further provides a system for using a global variable, where the system for using a global variable includes a processor, a memory, and a program for using a global variable stored in the memory and executable on the processor, and the program for using a global variable, when executed by the processor, implements the steps of the method for using a global variable as described above.
In addition, to achieve the above object, another aspect of the present application further provides a computer-readable storage medium, on which a global variable using program is stored, and when the global variable using program is executed by a processor, the method for using the global variable as described above is implemented.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application 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 application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. 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.
It should be noted that in the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The application can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
While alternative embodiments of the present application have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following appended claims be interpreted as including alternative embodiments and all such alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for using a global variable, the method comprising:
acquiring a timestamp of a first global variable, wherein the first global variable is a global variable of a program to be executed;
determining whether the first global variable is changed according to the timestamp;
and when the first global variable is determined not to be changed, acquiring a second global variable backed up by the read thread processing function so as to perform functional operation by using the second global variable.
2. The method of using global variables according to claim 1, wherein the step of determining whether the first global variable has changed based on the timestamp comprises:
comparing the timestamp of the first global variable with the timestamp of the second global variable stored in the read thread;
and when the comparison is consistent, confirming that the first global variable is not changed.
3. The method of using global variables according to claim 1, wherein said step of determining whether the first global variable has changed based on the timestamp is followed by the steps of:
and when the first global variable is determined to be changed, assigning the first global variable to the read thread processing function so as to use the first global variable to perform the functional operation.
4. The method of using global variables according to claim 3, wherein the step of assigning the first global variable to the read thread processing function for the functional operation using the first global variable is preceded by the step of:
acquiring the state of a thread lock;
when the state of the thread lock is an unlocking state, acquiring the first global variable in the thread lock;
and assigning the first global variable to the read thread processing function.
5. The method of using a global variable as claimed in claim 4, wherein said step of obtaining the state of the thread lock is followed by the steps of:
and if the state of the thread lock is an occupied state, applying for writing the lock so as to read the first global variable in the thread lock.
6. The method of using global variables according to claim 4, wherein said step of assigning said first global variable to said read thread processing function is followed by the steps of:
and modifying the timestamp of the first global variable into the timestamp of the first global variable backed up by the read thread processing function, and releasing the thread lock.
7. The method of using global variables according to claim 1, wherein after the step of obtaining a second global variable backed up by a read thread processing function to perform a functional operation using the second global variable, the method further comprises:
and displaying the result of the functional operation to a display interface.
8. An apparatus for using a global variable, comprising:
the system comprises a first acquisition module, a second acquisition module and a control module, wherein the first acquisition module is used for acquiring a timestamp of a first global variable, and the first global variable is a global variable of a program to be executed;
a determining module, configured to determine whether the first global variable is changed according to the timestamp;
and the second acquisition module is used for acquiring a second global variable backed up by the read thread processing function when the first global variable is determined not to be changed so as to perform functional operation by using the second global variable.
9. Use system of global variables, characterized in that the use of global variables comprises a processor, a memory and a use program of global variables stored on the memory and executable on the processor, the use program of global variables implementing the steps of the use method of global variables according to any of claims 1-7 when executed by the processor.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a use of global variables, which when executed by a processor implement the steps of the use of global variables according to any one of claims 1 to 7.
CN202011515034.6A 2020-12-18 2020-12-18 Global variable using method, device, system and computer readable storage medium Pending CN112596877A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011515034.6A CN112596877A (en) 2020-12-18 2020-12-18 Global variable using method, device, system and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011515034.6A CN112596877A (en) 2020-12-18 2020-12-18 Global variable using method, device, system and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN112596877A true CN112596877A (en) 2021-04-02

Family

ID=75199773

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011515034.6A Pending CN112596877A (en) 2020-12-18 2020-12-18 Global variable using method, device, system and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN112596877A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113360280A (en) * 2021-06-02 2021-09-07 西安中锐创联科技有限公司 Simulation curve display method based on multi-thread operation and dynamic global variable processing
CN113656111A (en) * 2021-09-06 2021-11-16 新华三信息安全技术有限公司 Pointer variable release method and device
CN114168607A (en) * 2021-12-13 2022-03-11 工银科技有限公司 Global serial number generation method, device, equipment, medium and product
CN114168077A (en) * 2021-12-07 2022-03-11 深圳忆联信息系统有限公司 Timestamp management method and device for solid state disk, computer equipment and storage medium
CN116069396A (en) * 2023-03-01 2023-05-05 浪潮电子信息产业股份有限公司 A detection method, device, equipment and medium for multi-core CPU out-of-order execution

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198978A1 (en) * 2006-02-22 2007-08-23 David Dice Methods and apparatus to implement parallel transactions
US9785735B1 (en) * 2016-10-11 2017-10-10 International Business Machines Corporation Parallel incremental global routing
KR101823129B1 (en) * 2016-11-24 2018-03-09 주식회사 실크로드소프트 Computer program, method and apparatus for distributing resource of processor
KR20180058661A (en) * 2016-11-24 2018-06-01 주식회사 실크로드소프트 Computer program, method and apparatus for distributing resource of processor
CN108733543A (en) * 2017-04-24 2018-11-02 北京京东尚科信息技术有限公司 A kind of method, apparatus of log analysis, electronic equipment and readable storage medium storing program for executing
CN108762942A (en) * 2018-04-12 2018-11-06 武汉斗鱼网络科技有限公司 Multi-threaded Access Methods and device
CN109189671A (en) * 2018-08-10 2019-01-11 百富计算机技术(深圳)有限公司 Successively folder forces formula variable localization method, system and terminal device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198978A1 (en) * 2006-02-22 2007-08-23 David Dice Methods and apparatus to implement parallel transactions
US9785735B1 (en) * 2016-10-11 2017-10-10 International Business Machines Corporation Parallel incremental global routing
KR101823129B1 (en) * 2016-11-24 2018-03-09 주식회사 실크로드소프트 Computer program, method and apparatus for distributing resource of processor
KR20180058661A (en) * 2016-11-24 2018-06-01 주식회사 실크로드소프트 Computer program, method and apparatus for distributing resource of processor
CN108733543A (en) * 2017-04-24 2018-11-02 北京京东尚科信息技术有限公司 A kind of method, apparatus of log analysis, electronic equipment and readable storage medium storing program for executing
CN108762942A (en) * 2018-04-12 2018-11-06 武汉斗鱼网络科技有限公司 Multi-threaded Access Methods and device
CN109189671A (en) * 2018-08-10 2019-01-11 百富计算机技术(深圳)有限公司 Successively folder forces formula variable localization method, system and terminal device

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113360280A (en) * 2021-06-02 2021-09-07 西安中锐创联科技有限公司 Simulation curve display method based on multi-thread operation and dynamic global variable processing
CN113360280B (en) * 2021-06-02 2023-11-28 西安中锐创联科技有限公司 Simulation curve display method based on multithread operation and dynamic global variable processing
CN113656111A (en) * 2021-09-06 2021-11-16 新华三信息安全技术有限公司 Pointer variable release method and device
CN113656111B (en) * 2021-09-06 2025-01-21 新华三信息安全技术有限公司 A pointer variable release method and device
CN114168077A (en) * 2021-12-07 2022-03-11 深圳忆联信息系统有限公司 Timestamp management method and device for solid state disk, computer equipment and storage medium
CN114168607A (en) * 2021-12-13 2022-03-11 工银科技有限公司 Global serial number generation method, device, equipment, medium and product
CN116069396A (en) * 2023-03-01 2023-05-05 浪潮电子信息产业股份有限公司 A detection method, device, equipment and medium for multi-core CPU out-of-order execution

Similar Documents

Publication Publication Date Title
CN112596877A (en) Global variable using method, device, system and computer readable storage medium
US8812451B2 (en) Programming model for synchronizing browser caches across devices and web services
US9652220B2 (en) Zero down-time deployment of new application versions
CN113297317B (en) Data table synchronization method, device, electronic equipment and storage medium
JP2014191604A5 (en)
WO2019056494A1 (en) Chart generation method, device, computer apparatus, and storage medium
CN109471901B (en) Data synchronization method and device
CN115237422A (en) Code compiling method, device, computer equipment and storage medium
US10514993B2 (en) Analyzing large-scale data processing jobs
CN112540808A (en) Method for recording program behavior level calling relation and related equipment
CN110244951B (en) Application publishing method and device
CN106843912B (en) Page information acquisition method and device
CN111581219A (en) Monitoring data acquisition method and device
CN117520450A (en) Synchronization method and device of process formula and semiconductor process equipment
JP2017220142A (en) Programming device
CN113761005A (en) Metadata configuration method, device, electronic device and storage medium
US10409651B2 (en) Incremental workflow execution
CN113971074B (en) Transaction processing method, transaction processing device, electronic equipment and computer readable storage medium
JP2017054217A (en) Test support apparatus, test support method, and test support program
CN111737784B (en) Board selection and configuration method and equipment for ZXMP S385 subrack based on digital three-dimensional
US20180081780A1 (en) Trace-information management system, trace-information management method, and trace-information management program product
CN114138646A (en) CAD resource verification method and device, storage medium and processor
CN115630025A (en) System and method for monitoring file changes in a shared file system
CN112667463A (en) Application system baseline state monitoring method and device
CN113204533A (en) Log level adjusting method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210402