Git Product home page Git Product logo

Comments (2)

senghoo avatar senghoo commented on June 29, 2024

我觉得这方面用什么上锁模式其实没什么太大差别。用互斥锁、原子变量还是用Once。(其实Once内部实现就是原子变量),就是看起来语意更清晰一些。

就算用Once,也可以实现多个实例 也就是多一个Once,还有工厂函数和全局变量。

from golang-design-pattern.

dakangshuji avatar dakangshuji commented on June 29, 2024

我觉得这方面用什么上锁模式其实没什么太大差别。用互斥锁、原子变量还是用Once。(其实Once内部实现就是原子变量),就是看起来语意更清晰一些。

就算用Once,也可以实现多个实例 也就是多一个Once,还有工厂函数和全局变量。

你说的有道理,我后来又试了一下,的确是声明多个once就可以了。看来是我误解了sync.Once.Do()的用法

from golang-design-pattern.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.