Take a write lock that will be released when the function has finished running
time in ms to wait to get the lock. Null mean infinite.
Take a write lock that will be released when the function has finished running