---
title: "Oxidizing OCaml: Data Race Freedom"
description: "Jane Street's OCaml extensions use a new `sync` mode to make data races statically unrepresentable in multicore OCaml 5."
url: "https://swe.quest/articles/oxidizing-ocaml-data-race-freedom-67442324c35f0e1c"
canonical: "https://blog.janestreet.com/oxidizing-ocaml-parallelism/"
source: "Jane Street Tech Blog"
published: "2023-09-01"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 15
tags: ["functional-programming","type-systems","concurrency","language-design","memory-safety"]
---

# Oxidizing OCaml: Data Race Freedom

A post on [Jane Street Tech Blog](https://swe.quest/sources/jane-street.md), published 2023-09-01, 15 min read, Deep dive. Original: [https://blog.janestreet.com/oxidizing-ocaml-parallelism/](https://blog.janestreet.com/oxidizing-ocaml-parallelism/)

## Summary

Jane Street's OCaml extensions use a new \`sync\` mode to make data races statically unrepresentable in multicore OCaml 5. Immutable and exclusively mutable values are \`sync\` and shareable across domains, while ordinary mutable values are \`unsync\` and confined to one domain. Mode-annotated mutexes give roughly safe-Rust capabilities. Capsules go further: they encapsulate unrestricted shared mutability, such as cyclic mutable structures, behind existentially typed keys, so code can mutate shared-ownership data in parallel without Rust-style fine-grained ownership tracking or unsafe code.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)
- [Type systems](https://swe.quest/tags/type-systems.md) (Compilers & runtimes)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)
- [Language design](https://swe.quest/tags/language-design.md) (Compilers & runtimes)
- [Memory safety](https://swe.quest/tags/memory-safety.md) (Security)

## Prerequisites

- OCaml basics ([easy posts on Functional programming](https://swe.quest/tags/functional-programming.md?difficulty=easy))
- Rust ownership and borrowing ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- OCaml locality and uniqueness modes ([easy posts on Functional programming](https://swe.quest/tags/functional-programming.md?difficulty=easy))
- existential types

## Keywords

OCaml 5, Jane Street, sync mode, capsules, Async, Rust

## Related posts

- [Oxidizing OCaml: Rust-Style Ownership](https://swe.quest/articles/oxidizing-ocaml-rust-style-ownership-5670c1001a0b9cc2.md): Jane Street Tech Blog · 2023-06-21 · Hard · 14 min read · Functional programming, Type systems, Language design, Memory management, Rust
  Jane Street's OCaml extensions add Rust-style ownership through mode axes.
- [Oxidizing OCaml: Locality](https://swe.quest/articles/oxidizing-ocaml-locality-b1f7bf98d1488c18.md): Jane Street Tech Blog · 2023-05-26 · Hard · 13 min read · Functional programming, Type systems, Memory management, Language design, Compilers
  Jane Street is extending OCaml with modes, starting with a locality mode that marks values as local (cannot escape their region) or global, so the compiler can stack-allocate short-lived values while keeping garbage collection everywhere else.
- [ICFP 2024](https://swe.quest/articles/icfp-2024-a2b848db9d4cf383.md): Jane Street Tech Blog · 2024-08-29 · Hard · 8 min read · Functional programming, Type systems, Language design, Memory management, Compilers
  Jane Street's OCaml Language team brings nine papers and talks to ICFP 2024 and describes its compiler-branch extensions: modal types (modes like local and unique) for Rust-like control over allocation and data-race-free parallelism, and a kind system for unboxed layouts.
- [Eliminating Data Races in Firefox – A Technical Report](https://swe.quest/articles/eliminating-data-races-in-firefox-a-technical-report-5763b33d1a4f6f94.md): Mozilla Hacks · 2021-04-06 · Hard · 11 min read · Concurrency, C & C++, Rust, Debugging, Static analysis
  Mozilla deployed ThreadSanitizer across Firefox's C/C++ and Rust code, using a compiled-in suppression list to gate new races in CI while legacy ones were triaged toward a "no data races" policy.
- [What the interns have wrought, 2022 edition](https://swe.quest/articles/what-the-interns-have-wrought-2022-edition-0f4dcf7e53f3e8d4.md): Jane Street Tech Blog · 2022-08-25 · Medium · 8 min read · Functional programming, Testing, Performance engineering, Developer tools, Engineering culture
  Three Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
