KC Sivaramakrishnan
kcsrk.info · Personal blog · on HN since 2015
KC Sivaramakrishnan, a researcher behind Multicore OCaml, writes about effect handlers, memory models, garbage collection and concurrency in OCaml.
What HN saysHN commenters recommend it for effect handler tutorials and slides, and for his paper on bounding data races, which discusses language memory models.
44HN people shared it
22linked it in comments
38stories submitted
1.2Kstory points
5 months agolast shared
2015people per year2026
Most-shared posts
- 1Effective Concurrency with Algebraic Effects in Multicore OCaml10 people · 156 points · first shared 2015 · 59 comments on HN
- 2Bounding Data Races in Space and Time [pdf]6 people · 1 points · first shared 2021 · discussion on HN
- 3A deep dive into Multicore OCaml garbage collector4 people · 166 points · first shared 2017 · 89 comments on HN
- 4OCaml 5.0 (prerelease) Manual: Effect handlers4 people · 6 points · first shared 2022 · 1 comments on HN
- 5Lock-free programming for the masses3 people · 196 points · first shared 2016 · 29 comments on HN
- 6State of Multicore OCaml [pdf]3 people · 160 points · first shared 2018 · 103 comments on HN
- 7Retrofitting Effect Handlers onto OCaml [pdf]3 people · 9 points · first shared 2021 · discussion on HN
- 8An O(x)Caml book that runs3 people · 6 points · first shared 2026 · discussion on HN
- 9Foundations for Hacking on OCaml2 people · 7 points · first shared 2025 · discussion on HN
- 10Uniqueness for Behavioural Types2 people · 4 points · first shared 2025 · discussion on HN
- 11Data Race Freedom in OxCaml2 people · 3 points · first shared 2026 · discussion on HN
- 12From Convergence to Confidence: Push-Button Verification for RDTs2 people · 3 points · first shared 2026 · discussion on HN
- 13Capsules: Compile-time lock discipline in OxCaml2 people · 2 points · first shared 2026 · discussion on HN
- 14Mergeable Replicated Data Types [pdf]2 people · 2 points · first shared 2019 · discussion on HN
- 15FIDES: End-to-end Compartments for Mixed-language Systems [pdf]2 people · 1 points · first shared 2026 · discussion on HN
What HN people wrote when they linked it
kcsrk · 2022-06-15
I would also recommend reading the effect handlers tutorial in OCaml 5.0 manual: https://kcsrk.info/webman/manual/effects.html.
sadiq · 2022-01-10
Good question!
https://github.com/ocaml-multicore/effects-examples has links to tutorials and examples for how effects can be used.
There's also some slides from KC's talk on effect handlers https://kcsrk.info/slides/handlers_edinburgh.pdf and materials from the CUFP 17 tutorial: https://github.com/ocamllabs/ocaml-effects-tutorial
https://gopiandcode.uk/logs/log-bye-bye-monads-algebraic-effects.html this is also a great introduction
cm3 · 2016-04-27
Multicore will take more time before it's stable, but it will be available via opam as another alternative OCaml toolchain until then. It's basically the result of KC's research: http://kcsrk.info/
4ad · 2024-12-12
There is this myth that having a weaker memory model can lead to higher performance. It sounds plausible, and it was a good idea to explore at the end of the 80s, but in the end it turned out that it's simply not substantiated by facts. Note that Apple Silicon is TSO.
Related: https://kcsrk.info/papers/pldi18-memory.pdf
Jalad · 2023-07-24
"Bounding data races in space and time" was an interesting one I saw recently! It's discussing the memory models of programming languages, and how they can fail pretty horribly when data races occur, and then talks about ways to avoid those. OCaml's multicore support is based on this work, meaning it's memory safety guarantees in when data races occur are pretty interesting
https://kcsrk.info/papers/pldi18-memory.pdf
https://youtube.com/watch?v=eXXzUzt_nAY
nequo · 2022-12-18
One answer is FPGAs:
https://signalsandthreads.com/programmable-hardware/
Also, OCaml’s garbage collector tries to minimize GC pauses. Here is a slide deck from a somewhat old talk about the now-released multicore GC:
https://kcsrk.info/multicore/gc/2017/07/06/multicore-ocaml-gc/
dgllghr · 2021-03-11
Cool! Glad to hear there is still work being done there. I was able to find the presentation I was thinking of: https://kcsrk.info/slides/handlers_edinburgh.pdf
Specifically the part about Preemptive Multithreading
dwenzek · 2020-09-01
Indeed, Irmin is a library to implement data stores which can be freely cloned, updated and merged along a model similar to git.
It separates the content from the actual store. So it can run as well on a file-system, on a git repository, in memory or in the browser (See for instance https://github.com/talex5/irmin-js).
As git, Irmin uses 3-way merge but applied to arbitrary values and not only files. As described here http://gazagnaire.org/pub/FGM15.pdf and generalized here
https://kcsrk.info/papers/oopsla19-mrdt.pdf
pjmlp · 2019-03-17
I only accept CS papers about it, do you have one at hand against Java favouring some random FP language instead?
Something of this level of quality, not random assertions on online forums.
http://kcsrk.info/multicore/gc/2017/07/06/multicore-ocaml-gc/
jules · 2018-10-15
How does this compare to Reagents? If I understand correctly, Reagents are the successor of Concurrent ML.
http://kcsrk.info/ocaml/multicore/2016/06/11/lock-free/
mc10 · 2018-10-06
Here are some recent (June 2018) slides about multicore OCaml that provide some extra information about effect handlers: http://kcsrk.info/slides/mcocaml_gallium.pdf
atombender · 2018-07-12
Posted a week ago: http://kcsrk.info/slides/mcocaml_gallium.pdf
Discussion: https://news.ycombinator.com/item?id=17416797
In short, expect it merged in mid-to-late 2019, maybe.
StreamBright · 2018-03-22
This is a pretty nice step forward to enable OCaml as a general purpose language that supports modern CPU architectures. A good intro here: http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multicore/
chenglou · 2017-07-31
Fwiw, OCaml algebraic effects are being implemented: http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multicore/
(And then there's https://reasonml.github.io, which I work on)
avsm · 2017-07-12
Multicore is picking up pace, and there will be a paper on the formalised memory model at this year's OCaml Workshop in Oxford in September.
There are a series of milestones to hit: the runtime GC, the memory model, the low-level programming model using one-shot continuations, and how it affects libraries running over it (e.g. algebraic effects). Each of these have associated papers and talks (see the ocamllabs.ionews section), so it's not quite fair to compare it to Duke Nukem Forever :-)
Some quick links to recent papers:
- memory model: http://kcsrk.info/papers/memory_model_ocaml17.pdf
- programming model: http://kcsrk.info/papers/awkward_effects_ml17.pdf
jnbiche · 2017-01-24
Current OCaml needn't worry about data races since no state is shared. Unfortunately, current OCaml also only exploits a single core, but it's so insanely fast that usually doesn't matter.
Upcoming OCaml multicore solves the shared state and data races problem with algebraic effects[0]. It is working, it's just not yet been released in mainline OCaml. Supposedly, that will happen this year, but we'll see.
0. http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multicore/
amirmc · 2016-04-05
You should checkout the work that KC has done over in OCaml Labs. Start with his blog [1] — there are things around Multicore, Effects and Profiling in there.
[1] http://kcsrk.info/blog/
jallmann · 2016-01-26
The canonical way to do concurrency these days is with a monadic library like Lwt or Async, which is a mechanism akin to promises/deferreds. They have their own implementations of channels/events/streams/what-call-you-it.
There is some interesting work being done on an effects system [1] which would be another option for type-safe concurrency, hopefully it will land soon alongside the multicore work.
There is also the old fashioned way with the stdlib's Event module[2] (in conjunction with Thread), but that's not used as often, mostly because Lwt/Async offer richer, safer abstractions.
[1] http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multicore/
[2] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Event.html
nextaccountic · 2024-06-03
> Not sure how that's the same as "doesn't see a reason to solve data races". I see lots of reasons. I just think it is possible to achieve the security goals without it.
If Carbon doesn't prevent data races, then how exactly will it achieve memory safety? Will it implement something like OCaml's "Bounding Data Races in Space and Time"? [0]
If we ignore compiler optimizations, the problem with data races is that it may make you observe tearing (incomplete writes) and thus it's almost impossible to maintain safety invariants with them. But the job of a safe low level language is to give tools for the programmer to guarantee correctness of the unsafe parts. In the presence of data races, this is infeasible. So even if you find a way to ensure that data races aren't technically UB, data races happening in a low level language surely lead to UB elsewhere.
Ultimately this may end up showing as CVEs related to memory safety so I don't think you can achieve your security goals without preventing data races.
[0] https://kcsrk.info/papers/pldi18-memory.pdf
yawaramin · 2021-12-21
Multicore OCaml works using a thread-safe generational garbage collector. Each domain (i.e. thread) gets its own minor heap, and the major heap is shared. Each heap is GCd independently. The domain-level minor heaps are restricted so different domains can't write to each other's minor heap. And the shared major heap is protected with more bookkeeping. More details in https://kcsrk.info/multicore/gc/2017/07/06/multicore-ocaml-gc/
Scala of course just uses the set of GCs that are available on the JVM. OCaml's GC has an advantage in that it's optimized for quickly creating and collecting many small objects–perfect for functional programming. But some advanced JVM GCs probably come close to that.
The new effect system is basically 'resumable exceptions'. An effect is declared somewhat similarly to an exception. When the effect is 'thrown', it is handled by the nearest effect handler up the callstack. The difference from an exception is that once (if) it is handled, it actually resumes at the exact position in the code where it left off, not in a continuation created by a closure which is effectively what Scala and every other userland effect system does.
tialaramex · 2021-06-10
> In Rust it's not even possible to write such code.
What does "such code" mean though? Rust won't let you say that your mutable variables are just shared between threads, because that's unsafe. But if you say OK, I want atomic data types (and so they lack tearing and other things you were bothered about) then you can clone an Arc of them, and write code to manipulate the atomics whose consequences are just as under specified. It's just that now you have to spell out that this is what you wanted, writing e.g. std::sync::atomic::Ordering::Relaxed
If you later complain to me that this code surprised you because the memory ordering wasn't what you expected, I will point at that symbol. If you wanted some specific ordering then "Relaxed" was wrong.
> My point is that the assumption that a == b is invalid if x is a global variable.
No it isn't? This is an important optimisation, which you would prefer to sacrifice rather than just writing what you mean in the first place.
> if you've any relevant references / descriptions of their memory model, let me know!
https://kcsrk.info/papers/pldi18-memory.pdf
Zababa · 2021-07-27
Multicore is coming along, you can read the latest news here: https://discuss.ocaml.org/t/multicore-ocaml-june-2021/8134
In terms of performance, there is this paper https://kcsrk.info/papers/system_effects_feb_18.pdf where on a single core async OCaml and effect OCaml are close to Go's net/http, and there is also this project https://github.com/ocaml-multicore/retro-httpaf-bench but I haven't see any results from it.