Is double checked locking safe?

Double checked locking can be unsafe in some situations and is sometimes considered an anti-pattern. However, it can be implemented in a safe way.