package bogue

  1. Overview
  2. Docs

Global variables with mutex

In a GUI, it is quite likely that a thread has to modify a variable owned by another thread. This is particularly true in Bogue. In order to protect against concurrent access to a shared variable, one should use a special kind of variable. This is the goal of this module.

Warning: working with threads is subtle, and using Var will not magically make all problems disappear. In particular if two variables want to access each other, you can end up into a stall, and freeze your program. This can happen more often that one thinks, because a Var may contain a Layout, and we know that sometimes layouts want to modify themselves...

Dependency graph
type 'a t
val create : 'a -> 'a t

create v returns a Var with initial value v.

val get : 'a t -> 'a
val set : 'a t -> 'a -> unit

set v value waits until no thread is accessing the Var v and then sets its value to value.

OCaml

Innovation. Community. Security.