How to fix Perforce error “Can’t clobber writable file” or Perforce Error Message – Can’t Clobber Writable File

The “can’t clobber writable file” error happens because Perforce is very cautious about accidentally overwriting (“clobbering”) work that you’ve done in your workspace. The normal Perforce workflow is to p4 sync a file (which puts it into your workspace as read-only) and then to p4 edit it if you want to modify it (this makes … Read more

Is synchronization within an HttpSession feasible?

I found this nice explanation in spring-mvc JavaDoc for WebUtils.getSessionMutex(): In many cases, the HttpSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session … Read more

using ThreadStatic variables with async/await

You could use CallContext.LogicalSetData and CallContext.LogicalGetData, but I recommend you don’t because they don’t support any kind of “cloning” when you use simple parallelism (Task.WhenAny / Task.WhenAll). I opened a UserVoice request for a more complete async-compatible “context”, explained in more detail in an MSDN forum post. It does not seem possible to build one … Read more

Is it possible to use mutex in multiprocessing case on Linux/UNIX ?

Mutual exclusion locks (mutexes) prevent multiple threads from simultaneously executing critical sections of code that access shared data (that is, mutexes are used to serialize the execution of threads). All mutexes must be global. A successful call for a mutex lock by way of mutex_lock() will cause another thread that is also trying to lock … Read more

std::mutex performance compared to win32 CRITICAL_SECTION

Please see my updates at the end of the answer, the situation has dramatically changed since Visual Studio 2015. The original answer is below. I made a very simple test and according to my measurements the std::mutex is around 50-70x slower than CRITICAL_SECTION. std::mutex: 18140574us CRITICAL_SECTION: 296874us Edit: After some more tests it turned out … Read more

Is it reasonable to synchronize on a local variable?

You are talking about the below case: public class MyClass { public void myMethod() { //Assume Customer is a Class Customer customer = getMyCustomer(); synchronized(customer) { //only one thread at a time can access customer object which ever holds the lock } } } In the above code, customer is a local reference variable, but … Read more