go-pattern-examples/creation/06_singleton/README.md
2020-05-02 17:36:50 +08:00

10 lines
329 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 单例模式
大名鼎鼎的单例模式,永远返回相同内存位置的绝对的、同一个实例对象。
Go有两种常见的单例模式
+ 使用懒惰模式的单例模式,使用`once.Do()`的双重同步检查保证线程安全生成单实例
+ 使用初始化的`init(){}`能力保证只生成一个实例