-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined Types for Concurrency #46
Comments
@GraemeSmith Final one for now. Note, these are not RFCs yet. But they are precursors to being written up as RFCs. You can see all the current RFCs here: https://github.com/Whiley/RFCs/tree/master/text |
@GraemeSmith In above example, have made |
@GraemeSmith Hmmmm, does that make sense? If |
@DavePearce seqlock_write shouldn't be interruptible by other writer threads, but it can be interrupted by reader threads. This is usually implemented using a spinlock which the writer must acquire before proceeding. |
Issues with the implementation of
|
Another interesting algorithm is the Treiber Stack. Here's a first approximation of a Whiley implementation:
One of the assumptions here is that pointer reads are atomic and, hence, there is no need for an undefined type (as with the The key question here is whether or not the assignment forces a copy. Because this is recursive structure, it must be implemented using a pointer under-the-hood. However, Under a simple ownership scheme, we have the following:
One question is how deallocation of a non-unique data structure is managed. NOTE: the challenge here is that it's not really clear what we could verify in Whiley about this data structure. Realistically, we want to reason over some kind of linearizability. |
Other possible algorithms to consider:
|
Other mutual exclusion algorithms include Dekker's But these, like Peterson's, aren't used in practice since a programmer wanting mutual exclusion would normally use a lock (if available in the language's library) or implement a lock using an atomic hardware primitive (like CAS, TAS, etc). |
Other interesting things to look at:
|
Another interesting question is how even to implement locks in a sensible fashion. For example, suppose we have:
The challenge here is that we are looking for some way to express useful things about stuff inbetween a |
The trieber stack is interesting because it's really about writing two pointers simultaneously (this is the linearisation point). The pointers being
The above fails because the two variables
Here, |
(see also #35 and #45)
The use of undefined types might also be useful in a concurrent setting. The rough idea is that, if we have a global variable with an undefined type (e.g.
?int
) then we don't need atomic reads / writes to that variable. The problem is how we actually use these variables to some useful effect. In particular, since reads and writes are notatomic
, reading from a variable of type?int
gives an undefined value (which e.g. could represent some value part way through a write by another thread). However, we can control these values using otheratomic
variables. The benefit of this is reduced time spent locking when reading or writing data.The concept of a
seqlock
is one algorithm that does something like this:This algorithm makes sense when we have a small number of writers and a larger number of readers. The key is that the readers never acquire locks and busy wait instead of blocking. Furthermore, the invariant is what guarantees that
data
is defined when thecount
is even. The loop invariant is probably needed to ensure this would verify (though this really needs to be thought through).The text was updated successfully, but these errors were encountered: