Simple C++ logger by using singleton pattern

前端 未结 4 1926
旧巷少年郎
旧巷少年郎 2021-02-09 17:28

Due to the flooding examples of implementing logger using Singleton pattern, I have just written a simple C++ logger in the same approach for my program. However, since the famo

4条回答
  •  走了就别回头了
    2021-02-09 17:35

    One approach would be to make sure that your first access to the logger comes before your app starts a second thread. By accessing the singleton at a time when you KNOW that there isn't any contention, you make sure that subsequent accesses will always find a pre-existing object and you should completely avoid the problem.

提交回复
热议问题