let noscope_create () =
  let state = Hashtbl.create 13 in
  let state_mutex = !mutex_create () in

  let get_mutex id =
    let mutex =
      state_mutex.lock ();
      try
        Hashtbl.find state id
      with Not_found ->
        let mutex = !mutex_create () in
          Hashtbl.add state id mutex;
          mutex
    in
      state_mutex.unlock ();
      mutex
  in

  let try_lock id =
    (get_mutex id).try_lock ()
  in

  let lock id =
    (get_mutex id).lock ()
  in

  let unlock id =
    (get_mutex id).unlock ()
  in
    {
      lock = lock;
      unlock = unlock;
      try_lock = try_lock;
    }