99 src="https://raw.githubusercontent.com/ocaml-multicore/kcas/main/doc/kcas.svg">
1010</a >
1111
12- # ** kcas ** &mdash ; STM based on lock-free MCAS
12+ # ** Kcas ** &mdash ; STM based on lock-free MCAS
1313
1414</div >
1515
16- [ ** kcas ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/index.html )
16+ [ ** Kcas ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/index.html )
1717provides a software transactional memory (STM) implementation based on an atomic
1818[ lock-free] ( https://en.wikipedia.org/wiki/Non-blocking_algorithm#Lock-freedom )
1919multi-word [ compare-and-set] ( https://en.wikipedia.org/wiki/Compare-and-swap )
2020(MCAS) algorithm
2121[ enhanced with read-only compare operations] ( doc/gkmz-with-read-only-cmp-ops.md )
2222and ability to block awaiting for changes.
2323
24- [ ** kcas_data ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas_data/Kcas_data/index.html )
24+ [ ** Kcas_data ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas_data/Kcas_data/index.html )
2525provides compositional lock-free data structures and primitives for
26- communication and synchronization implemented using ** kcas ** .
26+ communication and synchronization implemented using ** Kcas ** .
2727
2828Features and properties:
2929
@@ -53,7 +53,7 @@ cases, the non-blocking properties should allow use in many contexts including
5353those where locks are not acceptable, and the features provided should support
5454most practical needs.
5555
56- ** kcas ** is [ published on ** opam** ] ( https://opam.ocaml.org/packages/kcas/ ) and
56+ ** Kcas ** is [ published on ** opam** ] ( https://opam.ocaml.org/packages/kcas/ ) and
5757is distributed under the [ ISC license] ( LICENSE.md ) .
5858
5959[ ![ OCaml-CI Build Status] ( https://img.shields.io/endpoint?url=https%3A%2F%2Fci.ocamllabs.io%2Fbadge%2Focaml-multicore%2Fkcas%2Fmain&logo=ocaml&style=flat-square )] ( https://ci.ocamllabs.io/github/ocaml-multicore/kcas )
@@ -167,7 +167,7 @@ And now we have it:
167167
168168## Introduction
169169
170- The API of ** kcas ** is divided into submodules. The main modules are
170+ The API of ** Kcas ** is divided into submodules. The main modules are
171171
172172- [ ` Loc ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Loc/index.html ) ,
173173 providing an abstraction of _ shared memory locations_ ,
@@ -196,7 +196,7 @@ rebind `module Atomic = Loc` and then use the
196196and/or
197197[ ` Xt ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Xt/index.html ) APIs
198198to perform operations over multiple locations. This should not be done
199- just-in-case, however, as, even though ** kcas ** is efficient, it does naturally
199+ just-in-case, however, as, even though ** Kcas ** is efficient, it does naturally
200200have higher overhead than the Stdlib
201201[ ` Atomic ` ] ( https://v2.ocaml.org/api/Atomic.html ) .
202202
@@ -506,7 +506,7 @@ but this sort of [busy-wait](https://en.wikipedia.org/wiki/Busy_waiting) is
506506usually a _ bad idea_ and should be avoided. It is usually better to block in
507507such a way that the underlying domain can potentially perform other work.
508508
509- To support blocking ** kcas ** provides a
509+ To support blocking ** Kcas ** provides a
510510[ ` later ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Retry/index.html#val-later )
511511operation that amounts to raising a
512512[ ` Later ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Retry/index.html#exception-Later )
@@ -608,7 +608,7 @@ val pop_or_raise_if :
608608```
609609
610610This works, but creating, checking, and canceling timeouts properly can be a lot
611- of work. Therefore ** kcas ** also directly supports an optional ` timeoutf `
611+ of work. Therefore ** Kcas ** also directly supports an optional ` timeoutf `
612612argument for potentially blocking operations. For example, to perform a blocking
613613pop with a timeout, one can simply explicitly pass the desired timeout in
614614seconds:
@@ -621,7 +621,7 @@ Exception: Failure "Domain_local_timeout.set_timeoutf not implemented".
621621
622622Oops! What happened above is that the
623623[ _ domain local timeout_ ] ( https://github.com/ocaml-multicore/domain-local-timeout )
624- mechanism used by ** kcas ** was not implemented on the current domain. The idea
624+ mechanism used by ** Kcas ** was not implemented on the current domain. The idea
625625is that, in the future, concurrent schedulers provide the mechanism out of the
626626box, but there is also a default implementation using the Stdlib ` Thread ` and
627627` Unix ` modules that works on most platforms. However, to avoid direct
@@ -826,7 +826,7 @@ from scratch? For most professionals the answer might be along the lines of
826826_ "when I took my data structures course at the university"_ or _ "when I
827827interviewed for the software engineering position at Big Co"_ .
828828
829- ** kcas ** aims to be usable both
829+ ** Kcas ** aims to be usable both
830830
831831- for experts implementing correct and performant lock-free data structures, and
832832- for everyone gluing together programs using such data structures.
@@ -837,10 +837,10 @@ everyone should be doing every time they are writing concurrent programs.
837837Instead programmers should be able to reuse carefully constructed data
838838structures.
839839
840- One source of ready-made data structures is the
841- [ ** kcas_data ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas_data/Kcas_data/index.html )
842- package. Let's explore how we can leverage those data structures. Of course,
843- first we need to ` #require ` the package and we'll also open it for convenience:
840+ One source of ready-made data structures is
841+ [ ** Kcas_data ** ] ( https://ocaml-multicore.github.io/kcas/doc/kcas_data/Kcas_data/index.html ) .
842+ Let's explore how we can leverage those data structures. Of course, first we
843+ need to ` #require ` the package and we'll also open it for convenience:
844844
845845``` ocaml
846846# #require "kcas_data"
@@ -852,7 +852,7 @@ first we need to `#require` the package and we'll also open it for convenience:
852852The
853853[ dining philosophers problem] ( https://en.wikipedia.org/wiki/Dining_philosophers_problem )
854854is a well known classic synchronization problem. It is easy to solve with
855- ** kcas ** . If you are unfamiliar with the problem, please take a moment to read
855+ ** Kcas ** . If you are unfamiliar with the problem, please take a moment to read
856856the description of the problem.
857857
858858A handy concurrent data structure for solving the dining philosophers problem is
@@ -949,7 +949,7 @@ corresponding linked list node is added or moved to one end of the list. When
949949the cache overflows, the association whose node is at the other end of the list
950950is removed.
951951
952- The ** kcas_data ** package conveniently provides a
952+ ** Kcas_data ** conveniently provides a
953953[ ` Hashtbl ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas_data/Kcas_data/Hashtbl/index.html )
954954module providing a hash table implementation that mimics the Stdlib
955955[ ` Hashtbl ` ] ( https://v2.ocaml.org/api/Hashtbl.html ) module and a
@@ -1050,7 +1050,7 @@ an operation to change the capacity of the cache.
10501050
10511051### Programming with primitive operations
10521052
1053- In addition to the transactional interface, ** kcas ** also provides the
1053+ In addition to the transactional interface, ** Kcas ** also provides the
10541054[ ` Op ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Op/index.html )
10551055interface for performing a list of primitive operations. To program with
10561056primitive operations one simply makes a list of CAS operations using
@@ -1095,7 +1095,7 @@ val move : ?backoff:Backoff.t -> 'a list Loc.t -> 'a list Loc.t -> unit =
10951095
10961096Note that we also used the
10971097[ ` Backoff ` ] ( https://ocaml-multicore.github.io/kcas/doc/kcas/Kcas/Backoff/index.html )
1098- module provided by ** kcas ** above.
1098+ module provided by ** Kcas ** above.
10991099
11001100Now we can simply call ` move ` :
11011101
@@ -1147,7 +1147,7 @@ in a transaction is more expensive than updating individual locations
11471147atomically. Contention can cause transactions to retry and perform poorly.
11481148
11491149With that said, it is possible to create composable and reasonably well
1150- performing data structures using ** kcas ** . If a ** kcas ** based data structure is
1150+ performing data structures using ** Kcas ** . If a ** Kcas ** based data structure is
11511151performing much worse than a similar lock-free or lock-based data structure,
11521152then there is likely room to improve. Doing so will require good understanding
11531153of and careful attention to algorithmic details, such as which accessed need to
@@ -1277,7 +1277,7 @@ can see
12771277the updates are only done in case of success.
12781278
12791279A problem with the ` transfer ` function above is that it is not a composable
1280- transaction. The transaction mechanism provided by ** kcas ** does not implicitly
1280+ transaction. The transaction mechanism provided by ** Kcas ** does not implicitly
12811281perform rollbacks of changes made to locations, but it does offer low level
12821282support for nested conditional transactions.
12831283
@@ -1519,7 +1519,7 @@ val a_queue : int queue = {head = <abstr>; tail = <abstr>}
15191519- : int option = None
15201520```
15211521
1522- The queue implementation in this section is an example of using ** kcas ** to
1522+ The queue implementation in this section is an example of using ** Kcas ** to
15231523implement a fine-grained lock-free algorithm. Instead of recording all shared
15241524memory accesses and performing them atomically all at once, the implementation
15251525updates the tail outside of the transaction. This can potentially improve
@@ -1565,10 +1565,10 @@ understanding of how transactions work.
15651565We have previously casually talked about "transactions". Let's sharpen our
15661566understanding of transactions.
15671567
1568- In ** kcas ** , a _ transaction_ is essentially a function that can be called to
1568+ In ** Kcas ** , a _ transaction_ is essentially a function that can be called to
15691569prepare a specification of an operation or operations, in the form of a
15701570_ transaction log_ , that can then be _ attempted to be performed atomically_ by
1571- the underlying k-CAS-n-CMP algorithm provided by ** kcas ** .
1571+ the underlying k-CAS-n-CMP algorithm provided by ** Kcas ** .
15721572
15731573In other words, and simplifying a bit, when an explicit attempt is made to
15741574perform a transaction, it basically proceeds in phases:
@@ -2112,13 +2112,13 @@ significantly with relatively low effort.
21122112
21132113### Beware of torn reads
21142114
2115- The algorithm underlying ** kcas ** ensures that it is not possible to read
2115+ The algorithm underlying ** Kcas ** ensures that it is not possible to read
21162116uncommitted changes to shared memory locations and that an operation can only
21172117complete successfully if all of the accesses taken together were atomic. These
21182118are very strong guarantees and make it much easier to implement correct
21192119concurrent algorithms.
21202120
2121- Unfortunately, the transaction mechanism that ** kcas ** provides does not prevent
2121+ Unfortunately, the transaction mechanism that ** Kcas ** provides does not prevent
21222122one specific concurrency anomaly. When reading multiple locations, it is
21232123possible for a transaction to observe different locations at different times
21242124even though it is not possible for the transaction to commit successfully unless
@@ -2196,7 +2196,7 @@ having values from different committed transactions. This is something that
21962196needs to be kept in mind when writing transactions.
21972197
21982198To mitigate issues due to read skew and to also avoid problems with long running
2199- transactions, the ** kcas ** transaction mechanism automatically validates the
2199+ transactions, the ** Kcas ** transaction mechanism automatically validates the
22002200transaction log periodically when an access is made to the transaction log.
22012201Therefore an important guideline for writing transactions is that loops inside a
22022202transaction should always include an access of some shared memory location
0 commit comments