Ok, considered this.

I want to add the k,v pair to the hashtbl before other threads get the chance to run and possibly ignore another thread, for which the random number generator would return the same number (ok, chances for this are very very slim, but then maybe I should also remove the logic in get_key?)

As for the what if, the Lwt_main.run can only finish when it receives control again (e.g. when a Lwt.bind happens). This can only happen after the key has been added and the thread has successfully been ignored (and possibly even line 47 would at that time not yet be executed). So I'll leave this as is.