BUG: Make RandomState.set_state and RandomState.get_state threadsafe

Parts of RandomState.set_state and RandomState.get_state are not thread safe when we allow the GIL to be released. Synchronize access with RandomState.lock.