CN115794592B - Data competition detection method based on higher-order function - Google Patents

Data competition detection method based on higher-order function Download PDF

Info

Publication number
CN115794592B
CN115794592B CN202310094558.XA CN202310094558A CN115794592B CN 115794592 B CN115794592 B CN 115794592B CN 202310094558 A CN202310094558 A CN 202310094558A CN 115794592 B CN115794592 B CN 115794592B
Authority
CN
China
Prior art keywords
function
thread
event
access
parameters
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
CN202310094558.XA
Other languages
Chinese (zh)
Other versions
CN115794592A (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.)
Nanjing University of Posts and Telecommunications
Original Assignee
Nanjing University of Posts and Telecommunications
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 Nanjing University of Posts and Telecommunications filed Critical Nanjing University of Posts and Telecommunications
Priority to CN202310094558.XA priority Critical patent/CN115794592B/en
Publication of CN115794592A publication Critical patent/CN115794592A/en
Application granted granted Critical
Publication of CN115794592B publication Critical patent/CN115794592B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a data competition detection method based on a higher-order function, which comprises the following steps: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the reverse topological ordering order, and determining the analysis order of each function; sequentially selecting a function to be analyzed, traversing a control flow graph of the function, and obtaining a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer; carrying out occurrence sequence analysis on the access event based on the vector clock and the high-order function abstract; and eliminating access event pairs which are not satisfied by the conditions of data competition occurrence, and acquiring all possible data competition occurrence results. The invention can conveniently complete the substitution of the higher-order function parameters in the function abstract according to the corresponding relation between the real parameters and the shape parameters at the call point, effectively improves the efficiency of data competition information collection between the processes, and can perform high-efficiency occurrence sequence analysis by combining the vector clock and the function abstract.

Description

Data competition detection method based on higher-order function
Technical Field
The invention relates to the technical field of functional programming and program analysis, in particular to a data competition detection method based on a higher-order function.
Background
With the continuous development of computer technology, applications related to concurrency characteristics take on an important role. Under the concurrent environment, multiple threads can access the same memory location in parallel, and an error occurs, so that a lock is needed at the moment, and only one thread is allowed to access at the same time in the concurrent environment. Because of the uncertainty inside the concurrent program, the concurrent program is prone to problems, such as data race, atomic violation, deadlock, etc., and serious concurrent problems can cause program crash, so detection of these problems is very important. The most common and fundamental defect problem is data contention, and in a concurrent program, multiple threads access the same shared memory, one of the threads is a write operation, and the data contention is caused by performing mutual exclusion operation on the shared memory without locking, so that the data contention is difficult to be found once it occurs.
With the increasing size of software, function calls for programs today are very frequent because functions can be repeatedly called, which reduces the amount of code. Different calls of the same function have different parameters, so that it is difficult to distinguish which shared variables are accessed by the function, and therefore, the data competition information of the called function is different.
Higher order functions are an important feature of functional programming. In functional programming, the function is equally well-located with other data types, and can be passed to other functions as parameters or as return values for other functions. When in-process analysis of a plurality of parameters, the high-order function can flexibly generate the abstract taking the shape parameter as the function parameter, and corresponding parameters are reserved for the carrying-in of the real parameter in the function abstract, so that secondary analysis is avoided, and the efficiency of acquiring the inter-process data competition information is improved. Therefore, the invention provides a data competition detection method based on a higher-order function, which can effectively improve the efficiency of data competition information collection between processes.
Disclosure of Invention
This section is intended to outline some aspects of embodiments of the invention and to briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section as well as in the description summary and in the title of the application, to avoid obscuring the purpose of this section, the description summary and the title of the invention, which should not be used to limit the scope of the invention.
The present invention has been made in view of the above-described problems occurring in the prior art.
Therefore, the present invention is directed to a data race detection method based on higher-order functions, which solves the problem of collecting data race information that causes crash in concurrent programs.
In order to solve the technical problems, the invention provides the following technical scheme:
in a first aspect, an embodiment of the present invention provides a data race detection method based on a higher-order function, including: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the reverse topological ordering order, and determining the analysis order of each function;
sequentially selecting a function to be analyzed, traversing a control flow graph of the function, and obtaining a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer;
carrying out occurrence sequence analysis on the access event based on the vector clock and the high-order function abstract;
and eliminating access event pairs which are not satisfied by the conditions of data competition occurrence, and acquiring all possible data competition occurrence results.
The data competition detection method based on the higher-order function comprises the following steps: obtaining a higher-order function digest of each function includes,
sequentially selecting a P function to be analyzed, carrying out in-process analysis on each function, and defining a higher-order function, wherein parameters of the higher-order function are real parameters corresponding to a calling process;
the lock data set is collected for the lock statement node and the access event data set is collected for the access node as follows:
initializing a constraint set of a P function;
and collecting thread interaction primitive information for the thread interaction node.
The data competition detection method based on the higher-order function comprises the following steps: also included is a method of manufacturing a semiconductor device,
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of sentences including lock sentences, access sentences, function call sentences and thread interaction sentences, and transmitting analysis results of the sentences according to a traversing sequence;
representing the portions of the lock dataset and the access event dataset that relate to calling functions with parameters of defined higher-order functions;
let F (the number of bits of the id,l,vt, L) is a constraint function of the statement s to be analyzed, where id is the number of events iterated to the statement s,las a lock variable in statement s,vfor the shared variable in statement s,t is the thread name of the sentence s which interacts with the current thread, and L is the constraint set which is sequentially transmitted to the sentence s to be analyzed;
statement set { s|s i ∈S ,i=1, 2,3.. } where s is the program statement,is is a set of all program sentences, and constraint relation extraction equations corresponding to different sentences are constructed;
and after all the sentences in the P function are processed, storing the analysis result as a higher-order function abstract by taking the form parameters as the function parameters.
The data competition detection method based on the higher-order function comprises the following steps: the set of inter-process access events resulting from function calls and parameter passes includes,
for a function call statement, carrying out corresponding introduction on the access event function abstract in the form of the obtained higher-order function through the corresponding relation between real parameters and function parameters, obtaining an access event set in the process, obtaining a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
and recording the called function as a Q function at a function call node, transmitting the event number iterated to the current statement and the lock set into an access event of the Q function in the form of parameters, and correspondingly substituting the function parameters in the higher-order function abstract according to the corresponding relation between the shape parameters and the real parameters to obtain a complete inter-process analysis result of the function Q.
The data competition detection method based on the higher-order function comprises the following steps: also included is a method of manufacturing a semiconductor device,
creating a th thread at a thread function call node, namely a create method node, correspondingly substituting function parameters in a higher-order function abstract according to a corresponding relation between a shape parameter and a real parameter, and instantiating to obtain an access event set and a thread interaction primitive set of the th thread;
when the analysis results of all called functions are transferred to the corresponding function call points, the complete access event and thread interaction primitive information of each thread can be obtained.
The data competition detection method based on the higher-order function comprises the following steps: the occurrence analysis of access events based on the vector clock and the high-order function digest includes,
when analyzing the main thread, initializing the thread number gid as 0, and a local vector clock as clock= [1], abstracting the access event set and the vector clock in the event set GA, and storing the access event set with the same clock, so as to facilitate the subsequent occurrence sequence analysis;
after the analysis result of each thread is obtained, clock analysis is carried out from the interaction primitive set of the main thread;
creating thread primitives<id,t,create,th>: obtaining the thread number gid of the new thread th And vector clock th Increasing the number of steps of the clock value of the corresponding thread number of the vector clock of the t thread by 1, and analyzing the thread interaction primitive set of the th thread;
waiting thread primitives<id,t,join,th>: clock value clock of thread th to be waited th With its own vector clock t Comparing and updating the information, and increasing the number of steps of the clock value of the corresponding thread number of the vector clock of the t thread by 1;
storing access events between two primitives ti1 and ti2 of the same thread to the same event set GA i In, i.e. event number greater than id ti1 Less than id ti2 If ti1 is not preceded by other interaction primitives, then the event number goes from 0 to id ti1 If no other interaction primitive exists after ti2, the event number is id ti2 The event number to the last access event of the current function.
The data competition detection method based on the higher-order function comprises the following steps: excluding access event pairs that are not satisfied by conditions under which data race occurs, obtaining results of all possible occurrences of data race includes,
at the time of obtaining event set GA i That is, after all event sets in which data competition is possible to happen to the program, access event pairs which do not meet the occurrence condition are eliminated by taking the occurrence condition of the data competition as constraintI.e. the same variable, at least one access is a write operation, not protected by the same lock, and not having an occurrence sequence relationship, and finally obtaining an access event pair which may occur data contention.
In a second aspect, an embodiment of the present invention provides a data race detection system based on a higher-order function, including,
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological ordering, and determining the analysis sequence of each function;
the traversal module is used for sequentially selecting a function to be analyzed, traversing a control flow graph of the function and acquiring a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer;
the analysis module is used for carrying out occurrence sequence analysis on the access event based on the vector clock and the high-order function abstract;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition and acquiring all possible data competition results.
In a third aspect, embodiments of the present invention provide a computing device comprising:
a memory and a processor;
the memory is configured to store computer-executable instructions that, when executed by the one or more processors, cause the one or more processors to implement a high-order function-based data race detection method according to any embodiment of the present invention.
In a fourth aspect, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the high-order function-based data race detection method.
The invention has the beneficial effects that: according to the method, based on data competition detection of the higher-order function, the event set is accessed in the process through the higher-order function characteristics, the function abstract expressed in the higher-order function form is generated, substitution of higher-order function parameters in the function abstract can be conveniently completed at the call point according to the corresponding relation between the real parameters and the shape parameters, the efficiency of data competition information collection among the processes is effectively improved, and efficient occurrence sequence analysis is performed through combination of the vector clock and the function abstract.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Wherein:
fig. 1 is a flowchart of a data race detection method based on a higher-order function according to the present invention.
Detailed Description
In order that the above-recited objects, features and advantages of the present invention will become more readily apparent, a more particular description of the invention will be rendered by reference to specific embodiments thereof which are illustrated in the appended drawings.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, but the present invention may be practiced in other ways other than those described herein, and persons skilled in the art will readily appreciate that the present invention is not limited to the specific embodiments disclosed below.
Further, reference herein to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic can be included in at least one implementation of the invention. The appearances of the phrase "in one embodiment" in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments.
Further, in describing the embodiments of the present invention in detail, the cross-sectional view of the device structure is not partially enlarged to a general scale for convenience of description, and the schematic is only an example, which should not limit the scope of protection of the present invention. In addition, the three-dimensional dimensions of length, width and depth should be included in actual fabrication.
Example 1
Referring to fig. 1, for one embodiment of the present invention, there is provided a data race detection method based on a higher-order function, including:
as shown in fig. 1, the specific flow of the present invention is as follows:
s1: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the reverse topological ordering order, and determining the analysis order of each function.
S2: and sequentially selecting a function to be analyzed, traversing a control flow graph of the function, and obtaining a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer. It should be noted that:
carrying out in-process analysis on each function, and defining a higher-order function, wherein parameters of the higher-order function are real parameters corresponding to a calling process;
the lock data set is collected for the lock statement node and the access event data set is collected for the access node as follows:
and sequentially selecting a P function to be analyzed, initializing a constraint set L of the function, wherein ls is a lock set, access is an Access event set, inter is a primitive set, ls, access and Inter are null, and initializing the event number id=0. Abstracting an access event as e, wherein = < id, v, rw, ls > respectively represent an event number id, an accessed variable v, a read-write operation rw and a lock set ls formed by protecting the lock of the current statement;
creating a thread primitive event ti, wherein = < id, t, create, th > represents that the event number is id, and the t thread creates a th thread. Waiting thread primitive event ti is = < id, t, join, th > which indicates that the event number is id, and t thread waits for th thread execution to end;
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of sentences including lock sentences, access sentences, function call sentences and thread interaction sentences, and transmitting analysis results of the sentences according to a traversing sequence;
the parts of the lock data set and the access event data set related to the calling function are represented by parameters of defined high-order functions;
let F (the number of bits of the id,l,vt, L) is a constraint function of the statement s to be analyzed, where id is the number of events iterated to the statement s,las a lock variable in statement s,vfor the shared variable in the sentence s, t is the thread name of the sentence s interacting with the current thread, L represents the constraint set sequentially transferred to the sentence s to be analyzed, and if the current sentence s has no corresponding type variable, the current sentence s is expressed bynull come fromA representation;
according to statement set { s|s i ∈S ,i=1, 2, 3..where s is the program statement,ifor the row number corresponding to statement S, S is a set of all program statements), a constraint relation extraction equation corresponding to different statements is constructed:
if sentence s i For locking type statementslLock ()' wherein,lfor the lock type variable, the constraint relation extraction equation is:
L i =F(id,l,null,null,L)=<{l}∪L.ls,L.Access,L.Inter>
if sentence s i For unlocking type statementslUnlock (), among others,lfor the lock type variable, the constraint relation extraction equation is:
L i =F(id,l,null,null,L)=<L.ls-{l},L.Access,L.Inter>
if sentence s i For access type statements such as:v++ + wherein, the liquid crystal display device comprises a liquid crystal display device,vfor sharing type variables, reading and writing information of a current statement and sharing variables are obtained, and constraint relation extraction equations are as follows:
L i =F(id,null,v,null,L)=<L.ls,{<id+1,v,rw,ls>}∪L.Access,L.Inter>
if sentence s i For the create type statement th.create (), where th is the thread name of the newly created thread, the constraint relation extraction equation is:
L i =F(id,null,null,t,L)=<L.ls,L.Access,{<id+1,t,create,th>}∪L.Inter>
if sentence s i For the join type statement th.join (), where th is the thread name of the waiting thread, the constraint relation extraction equation is:
L i =F(id,null,null,t,L)=<L.ls,L.Access,{<id+1,t,join,th>}∪L.Inter>
after all sentences in the P function are processed, storing the analysis result as a function abstract in a higher-order function form by taking the form parameters as the function parametersλl.λk.λX.({<k+id,v,rw,l+ls>}∪{<k+id,t,create,th>,<k+id,t,join,th>}),xIs a form parameter of the P-function,vX,ls⊆XX={x 1 ,x 2 ,x 3 .., there may be a plurality of profile parameters,lis the set of locks held when the P function is called iteratively,kis the event number when the P function is called iteratively.
For a function call statement, carrying out corresponding introduction on the access event function abstract in the form of the obtained higher-order function through the corresponding relation between real parameters and function parameters, obtaining an access event set in the process, obtaining a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
recording the called function as a Q function at a function call node, transmitting the event number iterated to the current statement and the lock set into an access event of the Q function in the form of parameters, and correspondingly substituting the function parameters in the higher-order function abstract according to the corresponding relation between the shape parameters and the real parameters to obtain a complete inter-process analysis result of the function Q;
the constraint relation extraction equation of the function call statement is as follows: l (L) i =F(id,null,a,b..,null,L)=<L.ls,λlkX.{<k+id,x,rw,l+ls>}∪L.Access,L.Inter>Radix Ginseng RubralThe corresponding real parameter is L.ls, the shape parameterkThe corresponding real parameters are id, and the real parameters a, b.are substituted into the function of the shape parameters in sequenceXIs a kind of medium.
At a thread function call node, namely a create method node, a th thread is recorded and created, function parameters in a higher-order function abstract are substituted correspondingly according to the corresponding relation between the shape parameters and the real parameters, and the function parameters are called for the threadlIs a set of the air-holes,k0, instantiating and acquiring an access event set and a thread interaction primitive set of a th thread;
when the analysis results of all called functions are transferred to the corresponding function call points, the complete access event and thread interaction primitive information of each thread can be obtained.
S3: and carrying out occurrence sequence analysis on the access event based on the vector clock and the high-order function abstract. It should be noted that:
in the main thread analysis, the thread number gid is initialized to 0, a local vector clock= [1]]. The access event set and the vector clock are abstracted in the event set, namely GA: =<clock,{e 1 ,e 2 ,e 3 ...}>The method is used for storing the access event sets with the same clock, and facilitates subsequent occurrence sequence analysis.
After the analysis result of each thread is obtained, clock analysis is carried out from the interaction primitive set of the main thread;
creating thread primitives<id,t,create,th>: obtaining the thread number gid of the new thread th And vector clock th The number of steps of the clock value of the corresponding thread number of the vector clock of the t thread is increased by 1, and then the thread interaction primitive set of the th thread is analyzed as follows:
gid th =gid t +1,clock th =clock t ,clock th [gid th ]=1,clock t [gid t ]+=1;
wait thread primitive < id, t, join, th >: comparing and updating the clock value clock th of the waiting thread th with the own vector clock information, and increasing the clock value step number of the corresponding thread number of the vector clock of the t thread by 1 as follows:
clock t =max(clock t [i],clock th [i])(i=0,1,2...),clock t [gid t ]+=1;
storing access events between two primitives ti1 and ti2 of the same thread to the same event set GA i In, i.e. event number greater than id ti1 Less than id ti2 If ti1 is not preceded by other interaction primitives, then the event number goes from 0 to id ti1 If no other interaction primitive exists after ti2, the event number is id ti2 An event number to the last access event of the current function;
s4: and eliminating access event pairs which are not satisfied by the conditions of data competition occurrence, and acquiring all possible data competition occurrence results. It should be noted that:
at the time of obtaining event set GA i And after all event sets of the program, which are likely to generate data competition, access event pairs which do not meet the generation conditions are eliminated by taking the generation conditions of the data competition as constraints, namely, the access event pairs which are the same in variable, have at least one access as write operation, are not protected by the same lock and have no occurrence sequence relationship are finally obtained.
GA for two event sets 1 And GA (GA) 2 ,<clock 1 ,{<id 1 ,v 1 ,rw 1 ,ls 1 >}>∈GA 1 ,<clock 2 ,{<id 2 ,v 2 ,rw 2 ,ls 2 >}>∈GA 2 First, it is determined whether two event sets are not in order, i.e. ++ 1 [i]<=clock 2 [i]||clock 1 [i]<= clock 2 [i]) (i=0, 1, 2.) if the occurrence relationship is not satisfied, then determining whether the access events of the two event sets satisfy the condition that data race occurs as follows: access to the same variable:v 1 =v 2 the method comprises the steps of carrying out a first treatment on the surface of the At least one is a write operation: | (rw) 1 =r&&rw 2 =r); not protected by the same handle lock: ls (l) 1 ∩ls 2 =null;
The embodiment also provides a data contention detection system based on a higher-order function, which comprises:
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological ordering, and determining the analysis sequence of each function;
the traversal module is used for sequentially selecting a function to be analyzed, traversing a control flow graph of the function and acquiring a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer;
the analysis module is used for carrying out occurrence sequence analysis on the access event based on the vector clock and the high-order function abstract;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition and acquiring all possible data competition results.
The embodiment also provides a computing device, which is applicable to a data race detection method based on a higher-order function, and includes:
a memory and a processor; the memory is configured to store computer executable instructions, and the processor is configured to execute the computer executable instructions to implement a data race detection method based on a higher-order function as set forth in the above embodiment.
The computer device may be a terminal comprising a processor, a memory, a communication interface, a display screen and input means connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be keys, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
The present embodiment also provides a storage medium having stored thereon a computer program which, when executed by a processor, implements a data race detection method based on a higher-order function as proposed in the above embodiments.
The storage medium according to the present embodiment belongs to the same inventive concept as the data storage method according to the above embodiment, and technical details not described in detail in the present embodiment can be seen in the above embodiment, and the present embodiment has the same advantageous effects as the above embodiment.
Example 2
For another embodiment of the present invention, a verification test of a data race detection method based on a higher-order function is provided, and technical effects adopted in the method are verified and described.
The program code selected in this example is:
table 1: example code.
Figure SMS_1
In this example, the analysis sequence of the function is fun→th→main according to the reverse topology sequencing traversal function call graph, and the program has three threads in total, including main thread, t thread and t1 thread.
And carrying out in-process analysis on each function, and defining a high-order function, wherein parameters of the high-order function are real parameters corresponding to the calling process.
And sequentially selecting a P function to be analyzed, initializing a constraint set L of the function, wherein = < ls, access, inter >, ls, access and Inter are empty, and initializing the event number id=0.
This example first analyzes the fun function, initializes L fun =<ls,Access,Inter>Ls, access and Inter are empty, id fun =0。
Statement set { s|s for fun function 3 ,s 4 ,s 5 Constructing constraint relation extraction equations corresponding to different sentences as follows:
Statement s 3 For locking type statements, add constraints L 3 =F(0,m1,null,null,L)=<{m1}∪L.ls,L.Access,L.Inter>=<{m1},Ø,Ø>. Statement s 4 To write the shape parameter (p++), i.e., access type statement, add constraints: l (L) 4 = F(0,null,p,null,L)=<{m1},{<0+1,p,rw,{m1}>}∪L.Access,L.Inter>=<{m1},{<1,p,w,{m1}>},Ø>。
Statement s 5 For unlocking type statements, add constraints as follows:
L 5 =F(1,m1,null,null,L)=<L.ls-{m1},L.Access,L.Inter>=<Ø,{<1,p,w,{m1}>},Ø>。
after all sentences in the P function are processed, storing the analysis result as a function abstract in a higher-order function form by taking the form parameters as the function parametersλl.λk.λX.({<k+id,v,rw,l+ls>}∪{<k+id,t,create,th>,<k+id,t,join,th>})。
Obtaining the function abstract of the higher-order function form of the fun function asλl.λk.λp.{<k+1,p,w,l+{m1}>};
Recording the called function as a Q function at a function call node, transmitting the event number iterated to the current statement and the lock set into an access event of the Q function in the form of parameters, and correspondingly substituting the function parameters in the higher-order function abstract according to the corresponding relation between the shape parameters and the real parameters to obtain a complete inter-process analysis result of the function Q;
in analyzing th function, statement set { s|s } 8 ,s 9 ,s 10 }。
Statement s 8 To call a function statement, the higher-order function digest of the fun function isλl.λk.λp.{<k+1,p,w,l+{m1}>};
Adding constraints L 8 =F(0,null,v,null,L)=<L.ls,λl.λk.λX.{<k+1,p,w,l+{m1}>}∪L.Access,L.Inter>=<Ø,{<1,v,w, {m1}>},Ø>。
At a thread function call node, namely a create method node, a th thread is recorded and created, function parameters in a higher-order function abstract are substituted correspondingly according to the corresponding relation between the shape parameters and the real parameters, and the function parameters are called for the threadlIs a set of the air-holes,kthe instantiation obtains the access event set and thread interaction primitive set of the th thread at 0.
Statement s 9 Is a create type statement, with the following added constraints:
L 9 =F(0,null,null,t,L)=<L.ls,L.Access,{<0+1,th,create,t>}
∪L.Inter>=<Ø,{<1,v,w, {m1}>},{<2,th,create,t1>}>;
the higher-order function abstract of the fun function isλl.λk.λp.{<k+1,p,w,l+{m1}>Calling function parameters for threadslIs a set of the air-holes,kfor 0, substituting variable v for profile parameter p to obtain event set Access of t1 thread t1 ={<1,a,w,{m1}>};
Statement s 10 Is a join type statement, with the added constraints as follows:
L 10 =F(1,null,null,t,L)=<L.ls,L.Access,{<1+1,th,join,t1>}
∪L.Inter>=<Ø,{<1,v,w, {m1}>},{<2,th,create,t1>,<3,th,join,t1>}>;
the th function high order function abstract isλl.λk.λv.({<k+1,v,w,{m1}>}∪{<k+2,th,create,t1>,<k+3,th,join,t1>});
When the analysis results of all called functions are transferred to the corresponding function call points, the complete access event and thread interaction primitive information of each thread can be obtained.
Access event set Access of main thread of this example main ={<2,a,w,{m1,m2}>,<3,a,w,{m2}>Inter with primitive set main ={<1,main,create,t>,<4,main,join,t>Access event set Access of t thread t ={<1,a,w,{m1}>Inter with primitive set t = {<2,th,create,t1>,<3,th,join,t1>Access event set Access of t1 thread t1 ={<1,a,w,{m1}>}。
In analyzing the main thread, the thread number gid is initialized to 0, a local vector clock= [1].
In this example, when main function analysis is performed, the initialization thread number gid is 0, and the local vector clock= [1].
After the analysis result of each thread is obtained, clock analysis is performed from the primitives of the interaction primitive set of the main thread.
First, primitive set Interr for main thread main Analysis is performed for creating thread primitives<1,main,create,t>A main thread creation thread t representing a 1-event number, gets the thread number gid of the created thread t t =1 and vector clock t =[1,1]Then the clock value step number of the main thread corresponding to the thread number is increased by 1, and clock= [2 ]];
Storing access events between two primitives ti1 and ti2 of the same thread to the same event set GA i In (a) and (b);
primitive set Interr for t-thread t Analysis and creation of thread primitives<1,t,create,t1>Resulting in a thread number t1=2 for the created thread t1, clock t1 =[1,1,1]Then the clock value step number of the thread number corresponding to the t thread is increased by 1, clock is used for generating the clock signal t =[1,2]Because of the t1 thread interaction primitive, the access event of the t1 thread is stored into the event set GA 1 In (A), i.e. GA 1 =<[1,1,1], {<1,a,w,{m1}>}>The t-thread has two primitives, and stores access events smaller than the first create primitive event number 2 into the event set GA 2 In (A), i.e. GA 2 =<[1,1], {<1,a,w,{m1}>}>;
For Inter t A kind of electronic device<3,th,join,t1>Analysis is performed on the clock value clock of the thread t1 to be waited t1 With its own vector clock t Comparing and updating information, clock t =max(clock t [i],clock t1 [i])=[1,2,1](i=0, 1, 2), and then the clock value step number of the thread number corresponding to the t thread is increased by 1, clock t =[1,3,1]No access event between two primitives;
wait primitive for main thread<4,main,join,t>Obtaining clock= [3, 1]Storing access events between two primitives of main thread to the same event set GA 3 In (A), i.e. GA 3 =<[2],{<2,a,w,{m1,m2}>,<3,a,w,{m2}>}>。
After obtaining all event sets of the program, which are likely to generate data competition, access event pairs which do not meet the generation conditions are eliminated by taking the generation conditions of the data competition as constraint, namely, the access event pairs which are the same in variable, have at least one access as write operation, are not protected by the same lock and have no occurrence sequence relationship are finally obtained.
In this example, the above steps result in a set of events for which data race may occur.
GA 1 =<[1,1,1],{<1,a,w,{m1}>}>;
GA 2 =<[1,1], {<1,a,w,{m1}>}>;
GA 3 =<[2],{<2,a,w,{m1,m2}>,<3,a,w,{m2}>}>;
First, it is determined whether two event sets satisfy ≡ (clock 1 i]<=clock2[i]||clock1[i]<=clock2[i]) (i=0, 1, 2.) to ensure that there is no order of occurrence relationship, GA 1 And GA (GA) 3 、GA 2 And GA (GA) 3 The access event does not have an occurrence sequence relationship, wherein the access event can possibly generate data competition, whether the access event of the two event sets meets the condition of data competition occurrence is judged, and finally the access event pair meeting the condition of data competition occurrence can be obtained to be GA 2 A kind of electronic device<1,a,w,{m1}>And GA (GA) 3 A kind of electronic device<3,a,w,{m2}>。
It should be noted that the above embodiments are only for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solution of the present invention may be modified or substituted without departing from the spirit and scope of the technical solution of the present invention, which is intended to be covered in the scope of the claims of the present invention.

Claims (7)

1. A data competition detection method based on a higher-order function is characterized by comprising the following steps of: comprising the steps of (a) a step of,
preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the reverse topological ordering order, and determining the analysis order of each function;
sequentially selecting a function to be analyzed, traversing a control flow graph of the function, and obtaining a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer;
wherein obtaining the higher-order function digests of the respective functions includes,
sequentially selecting a P function to be analyzed, carrying out in-process analysis on each function, and defining a higher-order function, wherein parameters of the higher-order function are real parameters corresponding to a calling process;
the lock data set is collected for the lock statement node and the access event data set is collected for the access node as follows:
initializing a constraint set of a P function;
collecting thread interaction primitive information for a thread interaction node;
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of sentences including lock sentences, access sentences, function call sentences and thread interaction sentences, and transmitting analysis results of the sentences according to a traversing sequence;
representing the portions of the lock dataset and the access event dataset that relate to calling functions with parameters of defined higher-order functions;
let F (id, L, v, t, L) be the constraint function of the sentence s to be analyzed, wherein id is the event number iterated to the sentence s, L is the lock variable in the sentence s, v is the shared variable in the sentence s, t is the thread name in the sentence s which interacts with the current thread, and L is the constraint set which is sequentially transferred to the sentence s to be analyzed;
statement set { s|s i S, i=1, 2, 3..z, where S is a program statement, i is a line number corresponding to statement S, S is a set of all program statements, and constraint relation extraction equations corresponding to different statements are constructed;
after all sentences in the P function are processed, storing an analysis result as a higher-order function abstract by taking form parameters as function parameters;
wherein the set of inter-process access events resulting from function calls and parameter passes includes,
for a function call statement, carrying out corresponding introduction on the access event function abstract in the form of the obtained higher-order function through the corresponding relation between real parameters and function parameters, obtaining an access event set in the process, obtaining a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
recording the called function as a Q function at a function call node, transmitting the event number iterated to the current statement and the lock set into an access event of the Q function in the form of parameters, and correspondingly substituting the function parameters in the higher-order function abstract according to the corresponding relation between the shape parameters and the real parameters to obtain a complete inter-process analysis result of the function Q;
performing clock analysis on the thread interaction primitives, and storing access events with the same clock value in the same event set so as to perform occurrence sequence analysis on the inter-process access events;
and eliminating access event pairs which are not satisfied by the conditions of data competition occurrence, and acquiring all possible data competition occurrence results.
2. The method for detecting data contention based on higher-order functions as claimed in claim 1, wherein: also included is a method of manufacturing a semiconductor device,
creating a th thread at a thread function call node, namely a create method node, correspondingly substituting function parameters in a higher-order function abstract according to a corresponding relation between a shape parameter and a real parameter, and instantiating to obtain an access event set and a thread interaction primitive set of the th thread;
when the analysis results of all called functions are transferred to the corresponding function call points, the complete access event and thread interaction primitive information of each thread can be obtained.
3. The method for detecting data contention based on higher-order functions as claimed in claim 1, wherein: clock analysis of thread interaction primitives, storing access events having the same clock value in the same event set, for occurrence sequence analysis of the inter-process access events includes,
when analyzing the main thread, initializing the thread number gid as 0, and a local vector clock as clock= [1], abstracting the access event set and the vector clock in the event set GA, and storing the access event set with the same clock, so as to facilitate the subsequent occurrence sequence analysis;
after the analysis result of each thread is obtained, clock analysis is carried out from the interaction primitive set of the main thread;
creating thread primitives<id,t,create,th>: representing that the event number is id, the create is create, the t-thread creates the th thread, and the thread number gid of the new thread is obtained th And vector clock th Increasing the number of steps of the clock value of the corresponding thread number of the vector clock of the t thread by 1, and analyzing the thread interaction primitive set of the th thread;
waiting thread primitives<id,t,join,th>: indicating that the event number is id, join is waiting, t-thread waits for the end of the execution of the th thread, clock value clock of the th thread to be waited th With its own vector clock t Comparing and updating the information, and increasing the number of steps of the clock value of the corresponding thread number of the vector clock of the t thread by 1;
storing access events between two primitives ti1 and ti2 of the same thread to the same event set GA i In, i.e. event number greater than id ti1 Less than id ti2 If ti1 is not preceded by other interaction primitives, then the event number goes from 0 to id ti1 If no other interaction primitive exists after ti2, the event number is id ti2 The event number to the last access event of the current function.
4. The method for detecting data contention based on higher-order functions as claimed in claim 1, wherein: excluding access event pairs that are not satisfied by conditions under which data race occurs, obtaining results of all possible occurrences of data race includes,
at the time of obtaining event set GA i And after all event sets of the program, which are likely to generate data competition, access event pairs which do not meet the generation conditions are eliminated by taking the generation conditions of the data competition as constraints, namely, the access event pairs which are the same in variable, have at least one access as write operation, are not protected by the same lock and have no occurrence sequence relationship are finally obtained.
5. A data race detection system based on higher-order functions, comprising,
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological ordering, and determining the analysis sequence of each function;
the traversal module is used for sequentially selecting a function to be analyzed, traversing a control flow graph of the function and acquiring a higher-order function abstract of each function and an inter-process access event set generated by function call and parameter transfer;
wherein obtaining the higher-order function digests of the respective functions includes,
sequentially selecting a P function to be analyzed, carrying out in-process analysis on each function, and defining a higher-order function, wherein parameters of the higher-order function are real parameters corresponding to a calling process;
the lock data set is collected for the lock statement node and the access event data set is collected for the access node as follows:
initializing a constraint set of a P function;
collecting thread interaction primitive information for a thread interaction node;
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of sentences including lock sentences, access sentences, function call sentences and thread interaction sentences, and transmitting analysis results of the sentences according to a traversing sequence;
representing the portions of the lock dataset and the access event dataset that relate to calling functions with parameters of defined higher-order functions;
let F (id, L, v, t, L) be the constraint function of the sentence s to be analyzed, wherein id is the event number iterated to the sentence s, L is the lock variable in the sentence s, v is the shared variable in the sentence s, t is the thread name in the sentence s which interacts with the current thread, and L is the constraint set which is sequentially transferred to the sentence s to be analyzed;
statement set { s|s i S, i=1, 2, 3..z, where S is a program statement, i is a line number corresponding to statement S, S is a set of all program statements, and constraint relation extraction equations corresponding to different statements are constructed;
after all sentences in the P function are processed, storing an analysis result as a higher-order function abstract by taking form parameters as function parameters;
wherein the set of inter-process access events resulting from function calls and parameter passes includes,
for a function call statement, carrying out corresponding introduction on the access event function abstract in the form of the obtained higher-order function through the corresponding relation between real parameters and function parameters, obtaining an access event set in the process, obtaining a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
recording the called function as a Q function at a function call node, transmitting the event number iterated to the current statement and the lock set into an access event of the Q function in the form of parameters, and correspondingly substituting the function parameters in the higher-order function abstract according to the corresponding relation between the shape parameters and the real parameters to obtain a complete inter-process analysis result of the function Q;
the analysis module is used for carrying out clock analysis on the process interaction primitives and storing the access events with the same clock value in the same event set so as to carry out occurrence sequence analysis on the access events among the processes;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition and acquiring all possible data competition results.
6. A computing device, comprising:
a memory and a processor;
the memory is configured to store computer executable instructions, and the processor is configured to execute the computer executable instructions, which when executed by the processor implement the steps of a high order function based data race detection method as claimed in any one of claims 1 to 4.
7. A computer readable storage medium storing computer executable instructions which when executed by a processor implement the steps of a higher order function based data race detection method as claimed in any one of claims 1 to 4.
CN202310094558.XA 2023-02-10 2023-02-10 Data competition detection method based on higher-order function Active CN115794592B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310094558.XA CN115794592B (en) 2023-02-10 2023-02-10 Data competition detection method based on higher-order function

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310094558.XA CN115794592B (en) 2023-02-10 2023-02-10 Data competition detection method based on higher-order function

Publications (2)

Publication Number Publication Date
CN115794592A CN115794592A (en) 2023-03-14
CN115794592B true CN115794592B (en) 2023-07-04

Family

ID=85430772

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310094558.XA Active CN115794592B (en) 2023-02-10 2023-02-10 Data competition detection method based on higher-order function

Country Status (1)

Country Link
CN (1) CN115794592B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104077144A (en) * 2014-07-07 2014-10-01 西安交通大学 Data race detection and evidence generation method based on multithreaded program constraint building
CN109885489A (en) * 2019-01-31 2019-06-14 清华大学 Data contention detection method and device in driver
CN114238078A (en) * 2021-11-23 2022-03-25 南京邮电大学 Method for extracting dependency relationship between programs based on high-order function

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102073589B (en) * 2010-12-29 2013-07-03 北京邮电大学 Code static analysis-based data race detecting method and system thereof
CN102760095B (en) * 2011-04-25 2014-11-26 清华大学 Dynamic data race detection method based on static shared variable recognition
US11030105B2 (en) * 2014-07-14 2021-06-08 Oracle International Corporation Variable handles
WO2016122546A1 (en) * 2015-01-29 2016-08-04 Hewlett Packard Enterprise Development Lp Transactional key-value store
WO2016122548A1 (en) * 2015-01-29 2016-08-04 Hewlett Packard Enterprise Development Lp Hash index
US20220012575A1 (en) * 2020-07-09 2022-01-13 Femtosense, Inc. Methods and apparatus for localized processing within multicore neural networks
CN112817787B (en) * 2021-01-28 2023-03-10 南京大学 Automatic detection method for data competition of interrupt-driven embedded system
CN112965838B (en) * 2021-03-16 2024-04-19 支付宝(杭州)信息技术有限公司 Concurrent program data competition checking method and device
CN114428733A (en) * 2022-01-19 2022-05-03 南京大学 Kernel data competition detection method based on static program analysis and fuzzy test
CN114647575A (en) * 2022-02-23 2022-06-21 南京邮电大学 C + + inter-process anomaly analysis system and method based on high-order function
CN115098108A (en) * 2022-06-22 2022-09-23 南京邮电大学 Lightweight context sensitive pointer analysis method based on high-order function

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104077144A (en) * 2014-07-07 2014-10-01 西安交通大学 Data race detection and evidence generation method based on multithreaded program constraint building
CN109885489A (en) * 2019-01-31 2019-06-14 清华大学 Data contention detection method and device in driver
CN114238078A (en) * 2021-11-23 2022-03-25 南京邮电大学 Method for extracting dependency relationship between programs based on high-order function

Also Published As

Publication number Publication date
CN115794592A (en) 2023-03-14

Similar Documents

Publication Publication Date Title
Ivančić et al. Efficient SAT-based bounded model checking for software verification
JP4629682B2 (en) Efficient modeling method for embedded memory in finite memory test
CA2668121C (en) Lock-free state merging in parallelized constraint satisfaction problem solvers
Chen et al. Matrix completion via an alternating direction method
Bryant Binary decision diagrams
Bloem et al. Efficient decision procedures for model checking of linear time logic properties
JP2012516521A (en) Data processing using vector fields
Esparza et al. Parameterized verification of asynchronous shared-memory systems
Bouyer et al. Reachability in networks of register protocols under stochastic schedulers
Newton et al. A theoretical and numerical analysis of the worst-case size of reduced ordered binary decision diagrams
Beutner et al. AutoHyper: Explicit-state model checking for HyperLTL
CN115794592B (en) Data competition detection method based on higher-order function
Guo et al. Accelerating constraint-based causal discovery by shifting speed bottleneck
Rinberg et al. Brief Announcement: Intermediate Value Linearizability: A Quantitative Correctness Criterion
CN114417754A (en) Formalized identification method of combinational logic unit and related equipment
Codenotti et al. Parallel Complexity of Linear System Solution
Rubanov A high-performance subcircuit recognition method based on the nonlinear graph optimization
Chen et al. An abstract domain to infer linear absolute value equalities
Krauss et al. EDDY: A multi-core BDD package with dynamic memory management and reduced fragmentation
Chen et al. Parallel path detection for fraudulent accounts in banks based on graph analysis
Do et al. Sequential and Parallel Tools for Model Checking Conditional Stable Properties in a Layered Way
El-kustaban et al. Specification analysis of transactional memory using ITL and AnaTempura
Peri et al. Proving correctness of concurrent objects by validating linearization points
Cui et al. Language support for navigating architecture design in closed form
Alessi et al. LF+ in Coq for" fast and loose" reasoning

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