当前位置:网站首页>Synchronization mechanism of go (sync.mutex)
Synchronization mechanism of go (sync.mutex)
2022-07-26 13:43:00 【CS beat you】
One , Concurrent i++ operation
type atomicInt struct {
value int
lock sync.Mutex
}
func (a *atomicInt) increment() {
fmt.Println("safe increment")
fmt.Println(a.value)
func() {
a.lock.Lock()
defer a.lock.Unlock()
a.value++
}()
}
func (a *atomicInt) get() int {
a.lock.Lock()
defer a.lock.Unlock()
return a.value
}
func main() {
var a atomicInt
for i:=0;i<100;i++{
go func() {
a.increment()
}()
}
time.Sleep(time.Millisecond)
fmt.Println(a.get())
}
边栏推荐
- B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
- [collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
- Force deduction ----- the number of words in the string
- Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
- 银行业客户体验管理现状与优化策略分析
- 云智技术论坛工业专场 明天见!
- 时间复杂度和空间复杂度
- With frequent data leakage and deletion events, how should enterprises build a security defense line?
- Photoshop(CC2020)未完
- SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
猜你喜欢
![[oauth2] VII. Wechat oauth2 authorized login](/img/1a/3f2b9fc57759a1fa3fda1451492e5c.png)
[oauth2] VII. Wechat oauth2 authorized login

Photoshop(CC2020)未完
![[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from](/img/f6/03e39799db36c33a58127359aa2794.png)
[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from

Zhou Wei: look for non consensual investment opportunities to accompany the founding team that delays satisfaction

One stroke problem (Chinese postman problem)

JS get the current time, time and timestamp conversion

How to write the introduction of GIS method journals and papers?

The last time I heard about eBay, or the last time

Uncover the secret of white hat: 100 billion black products on the Internet scare musk away

Solution 5g technology helps build smart Parks
随机推荐
我们被一个 kong 的性能 bug 折腾了一个通宵
The.Net webapi uses groupname to group controllers to render the swagger UI
(Reprint) creation methods of various points in ArcGIS Engine
Win11+vs2019 configuration yolox
Codeforces round 810 (Div. 2) [competition record]
One stroke problem (Chinese postman problem)
Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase
Pytoch learning notes (I) installation and use of common functions
Photoshop(CC2020)未完
B+ tree (5) introduction to MyISAM -- MySQL from getting started to mastering (17)
【Oauth2】五、OAuth2LoginAuthenticationFilter
Golang port scanning design
Photoshop (cc2020) unfinished
Why does WPS refuse advertising?
Activity.onStop() 延迟10秒?精彩绝伦的排查历程
flutter多渠道打包运行
B+ tree (4) joint index -- MySQL from entry to proficiency (16)
【OAuth2】八、OAuth2登录的配置逻辑-OAuth2LoginConfigurer和OAuth2ClientConfigurer
JSON数据传递参数&日期型参数传递
Videojs to canvas pause, play, switch video