Explain how you would implement a thread-safe singleton pattern in your preferred programming language.