text stringlengths 128 2.05k |
|---|
Now for [MATH] , it is sufficient to combine Propositions and : if [MATH] , then [MATH] , where [MATH] and [MATH] . Then [EQUATION] |
Here [MATH] , and so the occurrences of [MATH] in [MATH] correspond exactly to occurrences of [MATH] in [MATH] The theorem is proved. |
The theorem ensures that the sequence [MATH] grows as depicted in Fig. . The two visible straight lines correspond to the symbols of the Fibonacci word equal to [MATH] (the upper line) or [MATH] (the lower line). |
Fibonacci-regular representation A sequence [MATH] is said to be Fibonacci-regular if there exist an integer [MATH] , a row vector [MATH] of dimension [MATH] a column vector [MATH] of dimension [MATH] and a [MATH] matrix-valued morphism [MATH] on [MATH] |
such that [EQUATION] for all canonical Fibonacci representations [MATH] The triple [MATH] is called a linear representation see, for example, |
Berstel gave the following linear representation for the function [MATH] we mentioned previously in Section [EQUATION] Hence [MATH] is Fibonacci-regular. |
We can find a similar representation for the function [MATH] For technical reasons it is easier to deal with the reversed Fibonacci representation; one can then obtain the ordinary linear representation by interchanging the roles of the vectors and taking the transposes of the matrices. |
Theorem 2 [MATH] has the reversed linear representation [MATH] , where [EQUATION] Proof. Define [MATH] if [MATH] is a valid canonical representation (that is, containing no leading zeroes, and no two consecutive 1’s), and [MATH] otherwise. It suffices to show, for all [MATH] and [MATH] , that |
[EQUATION] Once we prove this, it is then easy to see (using induction on [MATH] that, if [MATH] is the Fibonacci representation of [MATH] , then |
[MATH] , where [MATH] is the reversal of [MATH] Thus it suffices to verify Eq. ( ). This is equivalent to proving the following identities for [MATH] |
[EQUATION] Identities ( ) and ( 10 ) are particular cases of Proposition (b). To prove ( ), consider separately two cases: if [MATH] ends with an even number of zeros, then [MATH] due to Proposition (b) and [MATH] due to Proposition , so the identity holds. If [MATH] ends with an odd number of zeros, [MATH] [MATH] , th... |
[EQUATION] On the other hand, due to Propositions and [EQUATION] Comparing these equalities, we get ( ). To prove ( ), it is sufficient to use Proposition to get |
[EQUATION] and then to use ( ) twice, for [MATH] and for [MATH] To prove ( 11 ), it is sufficient to use Propositions and to get |
[EQUATION] Now ( 11 ) is obtained immediately by summing up ( ) applied to [MATH] and to [MATH] Finally, to prove ( 12 ), we again have to consider two cases. If [MATH] [MATH] , then due to Proposition [MATH] [MATH] [MATH] , and the equality holds. If now [MATH] [MATH] , then ( 12 ) immediately simplifies with Proposit... |
[EQUATION] Applying Proposition , we reduce it to [EQUATION] or, writing [MATH] and applying Proposition again, [EQUATION] But this is exactly ( ) since [MATH] References |
# Source: arxiv 1806.09851 # Title: Verification of Shared-Reading Synchronisers # Sections: all # Downloaded: 2026-03-03T02:30:36.260170+00:00 |
Verification of Shared-Reading Synchronisers Abstract Synchronisation classes are an important building block for shared memory concurrent programs. Thus to reason about such programs, it is important to be able to verify the implementation of these synchronisation classes, considering atomic operations as the synchron... |
shared-reading synchronisers. We use permission-based Separation Logic to describe the behaviour of the main atomic operations, and the basis for our technique is formed by a specification for class |
AtomicInteger , which is commonly used to implement synchronisation classes in java util concurrent . To demonstrate the applicability of our approach, we mechanically verify the implementation of various synchronisation classes like |
Semaphore CountDownLatch and Lock Introduction As our society is increasingly becoming more digital, there is an urgent need for techniques that can improve the performance of software. Concurrency is commonly used to achieve this goal, as it allows to split bigger tasks into multiple smaller tasks, which can be execut... |
In this paper, we consider this problem. We focus in particular on shared memory concurrent programs, where multiple threads interact and communicate via a common, shared memory. One of the main building blocks of such programs are synchronisation classes that control the access to a shared memory. We distinguish betwe... |
java util concurrent (JUC) provides several variations of both kinds of synchronisers, typically implemented on top of the AtomicInteger class. |
We proposed a technique to specify and verify exclusive access synchronisers, such as Lock , using permission-based Separation Logic |
Our paper extends this approach to cover also shared-reading synchronisers. The original approach identifies two main components that make up the specification of a synchroniser: (1) the value of the atomic variable, i.e. the atomic state, and (2) the views of the participating threads on the atomic state, i.e. the lat... |
In this paper, we make this approach more fine-grained, allowing a thread to obtain only a read permission to the shared memory location. We derive new specifications for the atomic operations that capture the possibility of obtaining both exclusive and partial access, and combine these into a new contract for the clas... |
AtomicInteger Applicability of the approach is demonstrated by discussing the verification of several commonly used synchronisers: |
Semaphore CountDownLatch and Lock All examples are mechanically verified using our VerCors tool-set The paper is structured as follows: Section |
briefly introduces permission-based Separation Logic. Section discusses several implementations of typical shared-reading synchronisers. Section |
derives the specifications for the three main atomic operations, using permission-based Separation Logic. Then, Section combines this into a contract for |
AtomicInteger , and Section shows how this is used to verify the synchronisation classes. Finally, Section concludes the paper, and discusses related work. |
Background This section briefly explains permission-based Separation Logic (PBSL) and its role in reasoning about concurrent programs. Concurrent Separation Logic (CSL) |
, which is an extension of SL , is a Hoare-style program logic to reason about multi-threaded programs. In addition to the predicates and operators from first order logic, CSL uses two new constructs in the specifications: (1) The points-to predicate: [MATH] describes that the location of the heap addressed by [MATH] i... |
O’Hearn developed required rules to reason about threads exchanging exclusive ownership of a memory location through a synchronisation construct |
. In the rules related to shared memory, the shared state is specified by a resource invariant : a predicate that expresses the properties of the shared variables that must be preserved in all the states visible by all the participating threads. The general judgement in CSL, denoted as [MATH] , expresses that with a re... |
: any thread that successfully obtains the lock acquires [MATH] and before releasing the lock it has to detach [MATH] from its local state. Verification of an atomic operation proceeds similar to verification of a class using a lock: (1) the thread executing an atomic operation acquires the global lock, (2) it adds the... |
[EQUATION] where [MATH] is the resource invariant, [MATH] is the empty heap, [MATH] indicates that the command [MATH] is executed atomically, [MATH] is the precondition for execution of the atomic operation, and [MATH] is the postcondition of the atomic operation. |
To enable reasoning about multiple threads simultaneously reading the same shared data, CSL has been extended with permissions to PBSL. This extension is necessary to specify and verify shared-reading synchronisations |
In PBSL, any access to location of the heap is decorated with a fractional permission [MATH] Any fraction [MATH] is interpreted as a read permission and the full permission [MATH] denotes a write permission (full ownership). Permissions can be transferred between threads at synchronisation points (including thread crea... |
[MATH] , where [MATH] is undefined if the result is greater than [MATH] Soundness of the logic ensures that the sum of all permissions to a location is never more than 1. Thus, at most one thread at a time can be writing to a location, and whenever a thread has a read permission, all other threads holding a permission ... |
In this paper we are using our VerCors specification language to specify and verify the behaviour of synchronisers (in Section ). The specification language of VerCors is an extension of the Java Modeling Language (JML) with PBSL. The standard SL notation of [MATH] for separating conjunction becomes |
** in our specifications, in order to avoid a syntactical clash with the multiplication operator of Java (and JML). Method and class specifications can be preceded by a |
given clause, declaring ghost parameters to method and classes. Ghost method parameters are passed at method calls, ghost class parameters are passed at type declaration and instance creation, resembling the parametric types mechanism of Java. This mechanism is used to pass resource invariants to classes. Furthermore, ... |
, by providing the name, typing and parameter declaration. The full grammar for the VerCors specification language is as follows: |
[EQUATION] where [MATH] denotes resource expressions (typical elements [MATH] ), [MATH] represents functional expressions (typical elements [MATH] ), [MATH] is the logical expressions of type boolean (typical elements [MATH] ), |
is an arbitrary type, vi is a variable name, is an abstract predicate of a special type resource field is a field reference, and |
pi denotes a fractional permission. Shared-reading Synchronisers In Java, volatile variables can be used as a communication mechanism between multiple threads. Writing to (or reading from) a volatile field has the same memory effect as if a monitor is released (or locked). Therefore when writing to a volatile variable,... |
The atomic package of JUC contains a set of atomic classes that define wrapper functions for private volatile fields with different types. Each atomic class defines three basic atomic operations. For example the |
AtomicInteger class exports get () for atomic read, set int for atomic write and compareAndSet int int for atomic conditional update. The |
compareAndSet int int method first atomically checks the current value of the volatile field and updates it to if it is equal to the expected value |
, otherwise it leaves the state unchanged, and then it returns a boolean to indicate whether the update succeeded. This AtomicInteger class is the basis for almost all synchroniser implementations in |
java util concurrent such as ReentrantLock and other classes implementing the interface Lock Semaphore CyclicBarrier and CountDownLatch |
Here we present (simplified) implementations of two different shared-reading synchronisation classes: Semaphore and CountDownLatch In our implementations, we stripped fairness conditions from the original soure code, i.e. we did not implement any algorithm to fairly pick the next candidate for the shared resource compe... |
. Finally, in Section we will demonstrate how these synchronisers are verified. In a Semaphore (see LABEL:lst:semaphoreimpl ) all participating threads compete with each other to acquire or release protected portions of the shared resource. In a concurrent program synchronised with a semaphore, any thread trying to acq... |
Next we consider a CountDownLatch Suppose we have an application with disjoint sets of active and passive threads, where active threads initially own a portion of the shared resource and passive threads wait for active threads to release their portions. |
CountDownLatch , as implemented in LABEL:lst:countdownlatchimpl blocks all the passive threads, until all active threads have released their portion of the shared resource. If the passive threads are unblocked, ownership of the shared resource is transferred to the passive threads. |
CountDownLatch maintaints a counter that denotes the number of active threads working on the shared resource. Each active thread, once finished, calls |
countDown () on the latch, which decreases the counter (see line ), to signal that it is done. The passive threads wait for the active threads by calling the blocking |
await () method on the latch. Inside this method, the passive threads are continuously reading the state of the latch until it reaches zero (line 19 ). In fact, the latch collectively accumulates the full shared resource from the active threads and the waiting passive threads can continue their task only when they see ... |
In summary, groups of threads involved in the synchronisation can be abstracted by their behavioral role If threads with an identical role share a resource (as in |
Semaphore ), then in order to obtain (or release) a portion of that resource, they have to participate in a compareAndSet -based competition. But, if threads have different roles (as the passive and active thread groups in |
CountDownLatch ) they can exchange the shared resource by reading the atomic variable that controls the access. Note however, active threads in the |
CountDownLatch still have to compete with each other to release their portions. In both of these synchronisers, the state of the volatile counter defines the remaining portion of the shared resource. Intuitively, associating the role of the threads, the state of the synchroniser and the portions of the shared resources... |
Reasoning about Atomics This section extends the formal specifications of the atomic operations presented in in such a way that they can be used to verify both exclusive access and shared-reading synchronisation constructs. |
We identified various synchronisation patterns using basic atomic operations. These synchronisation patterns show that a thread: (1) can both obtain or release resources by calling the |
compareAndSet (or simply cas operation, if it wins the competition, (2) may only obtain resources by calling the get operation, provided it meets the conditions imposed by the protocol on the thread’s view of the atomic variable, and (3) always releases resources by writing an atomic location using the |
set operation. To explain the essence of our specification, first, we focus on competitive resource acquisition using the cas operation. We start with a simple example that illustrates the behavior of atomic variables to see how a fraction of the shared resource is exchanged when an atomic variable is used as a shared-... |
Similar to the formalisation for exclusive access synchronisers , we partition the heap augmented with permissions into two disjoint parts, denoted [MATH] for atomic locations and [MATH] for non-atomic locations. For a given atomic variable [MATH] , we restrict the set of atomic operations to: (1) [MATH] for atomic rea... |
As an example, using a semaphore [MATH] to protect a location [MATH] , the value of the atomic location [MATH] (defined as atomic state) indicates the number of available fractions for the semaphore. The resource invariant for [MATH] associates the value of [MATH] with the maximum number of threads that concurrently ca... |
[EQUATION] In an implementation of the semaphore, any thread that wishes to acquire a portion of the shared resource must atomically decrement the value of [MATH] by [MATH] This transfers [MATH] of [MATH] from [MATH] to the calling thread. This fraction is stored back to [MATH] by releasing the semaphore, which increme... |
In the implementations of acquire and release , the executing thread with expected value [MATH] executes the atomic body of the cas operation. As justified by the atomic rule, to verify the body it obtains [MATH] . This gives full access of [MATH] , as well as [MATH] of [MATH] |
(provided the current state equals [MATH] ). The thread then updates [MATH] to [MATH] for acquire or [MATH] for release , and re-establishes [MATH] with [MATH] before leaving the body. To do so, the thread either acquires itself a [MATH] fraction of [MATH] or it releases a [MATH] fraction of [MATH] This example gives u... |
If we denote the shared resources to be protected by the atomic location [MATH] using [MATH] , then we can define the resource invariant as: |
[EQUATION] where [MATH] Using [MATH] , the atomic location [MATH] is interpreted as the owner of the resources for which the threads compete through the |
cas operation in order to obtain or release their permissions. Based on this general definition of resource invariant, we can specify the behavior of cas For a synchroniser [MATH] , if [MATH] maps the state of the synchroniser to the fractions with a maximum number of threads [MATH] , then we can axiomatise cas as foll... |
[EQUATION] where [MATH] denotes the cut-off subtraction over the fractions in [MATH] , defined as follows: [EQUATION] Surprisingly, the behaviors of both atomic read and write are more subtle than for the cas operation. This is because their behavior can differ from one case to another. In some cases, the atomic read o... |
and 19 in Listing LABEL:lst:semaphoreimpl line in Listing LABEL:lst:countdownlatchimpl . Also, the waiting threads in CountDownLatch (see line 19 from |
LABEL:lst:countdownlatchimpl ) obtain their fractions only when they realize that the latch has reached zero. In other cases, unconditional updates in the atomic writes require a |
rely-guarantee style of reasoning as the writing thread must adhere to a protocol which guarantees the safety of the write to the environment |
. This is thoroughly discussed and formalised by Amighi et al. . Here we extend the formal definition of the resource invariant from |
to associate the state of the atomic variable with the fractions of the resources. First, we explain some notations which are used in the definitions. |
A thread view is an atomic ghost field defined for each thread that stores the last visited value of the atomic state. Each view is indexed by the owning thread identifier and the ownership of a view is split between the owning thread and the resource invariant, thus, it can only be updated inside an atomic body. |
[MATH] denotes the vector of views, indexed by their thread identifiers. A vector of values pointed to by the views, indexed by the corresponding thread identifiers, is written [MATH] , while [MATH] denotes a vector such that the value of the item indexed with [MATH] in the vector of values [MATH] is equal to [MATH] . ... |
We decomposed the resource invariant into two components The first component is the global resource invariant that associates the resources to the global atomic state: |
[EQUATION] where: having fsbl for determining the feasibility of the values taken by the atomic location and all the thread views [MATH] is defined as follows: |
[EQUATION] the fraction of the resources is associated with the atomic state via [MATH] , and finally, [MATH] The second component associates the fractions of the resources to the thread views which can be exchanged through a collaborative synchronisation: |
[EQUATION] By giving a definition for [MATH] one can express when a thread with a particular knowledge may obtain the resource. The set absorbs the resources either through [MATH] to the atomic location or through [MATH] to the reader thread. This is formally specified in the contracts for the basic atomic operations w... |
Comparing the new contribution with , our formalised extension for shared-reading synchronisers can be summarised by the following steps: (1) an extension of the permission interval with [MATH] (2) associating the fractions of the shared resource to the global atomic state, (3) and updating the contract of cas using th... |
The next section presents how the specification from Figure translates into a contract for the AtomicInteger class, using our VerCors |
specification language. Contract of Atomic Integer The new contract of AtomicInteger is presented in LABEL:lst:SharedAtomicIntegerSpecification First we summarise the elements of the contract that are defined from our earlier work |
. Then, we explain our extensions regarding shared-reading synchronisers. /*@given Set<role> rs; given group (frac->resource) inv; |
given (role,int->frac) share; given (role,int,int-> boolean) trans; @*/ class AtomicInteger private volatile int value /*@group resource |
handle(role r,int d,frac p); @*/ /*@requires inv(share(S,v)); ensures (\forall* in rs: handle(r,v,1)); @*/ AtomicInteger int ); 11 /*@given |
role r, int d, frac p; requires handle(r,d,p) ** inv(share(r,d)); 13 ensures handle(r,\result,p) ** inv(share(r,\result)); @*/ public |
int get (); 15 /*@given role r, int d, frac p; 17 requires handle(r,d,p) ** trans(r,d,v); requires inv(share(S,v)) ** inv(share(r,d)); |
19 ensures handle(r,v,p);@*/ public void set int ); 21 /*@given role r, int m, frac p; 23 requires handle(r,x,p) ** trans(r,x,n) |
requires inv(share(S,n)-share(S,x)); 25 ensures \result==> (handle(r,n,p) ** inv(share(S,x) share(S,n)); ensures !\result==> (handle(r,x,p) |
** inv(share(S,n) share(S,x)); @*/ 27 boolean compareAndSet int int ); Listing 3: Contracts for AtomicInteger : Exclusive and Shared-reading |
LABEL:lst:SharedAtomicIntegerSpecification shows how the AtomicInteger class is parametrised by rs inv share trans , where rs is a set of roles abstracting participating threads, |
inv represents an abstract predicate as a resource invariant, specifying the shared resources to be protected by AtomicInteger , and |
share defines a function to associate the states of the atomic integer with a fraction of the shared resource; and trans is a boolean predicate, encoding all the valid transitions that a particular instance of |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.