go-deadlock | Online deadlock detection in go
kandi X-RAY | go-deadlock Summary
kandi X-RAY | go-deadlock Summary
Online deadlock detection in go (golang)
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of go-deadlock
go-deadlock Key Features
go-deadlock Examples and Code Snippets
Community Discussions
Trending Discussions on go-deadlock
QUESTION
I'm trying to implement graceful channel closing from receiver side.
Yes, I'm aware that this violates the channel closing rule:
But I want to implement such logic. Unfortunately, I fail into deadlock issue in the number of cases: the application just hangs for the unlimited time, trying to lock same locked Mutex
again.
So, I have 2 goroutines:
- one that will write into a channel and
- another that will receive data + will close channel from the receiver side.
My channel wrapped in the struct with sync.Mutex
and closed
boolean flag:
ANSWER
Answered 2018-Apr-01 at 09:07Send grabs the lock, then attempts to sends data down the channel. This may happen just after the 50th receive operation. There will be no more receives, so c.data <- data
blocks forever and consequently the Mutex is held forever.
For cancellation, use another channel (instead of the boolean) and a select statement in Send. You can also leverage the context package.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-deadlock
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page