1structure Sref :> Sref =
2struct
3
4   type 'a t = {mutex : Mutex.mutex, v : 'a ref}
5
6   fun new v = {mutex = Mutex.mutex(), v = ref v}
7
8   fun update {mutex,v} f =
9     Multithreading.synchronized "sref.update" mutex
10                                 (fn () => v := f (!v))
11   fun value {mutex,v} = !v
12
13end;
14