Preventing Atomicity Violations with Contracts