Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: A deadlock occurs when call the Wait() of a Cond associated with the RLocker of a RWMutex after call the Lock() of the RWMutex #7858

Closed
hyper0x opened this issue Apr 24, 2014 · 8 comments
Milestone

Comments

@hyper0x
Copy link

hyper0x commented Apr 24, 2014

// What does 'go version' print?
go 1.2.1

// What steps reproduce the problem?
// If possible, include a link to a program on play.golang.org.

Please see http://play.golang.org/p/519bXABwl_ .

When I comment 'rlocker.Lock()' in line 19 and run the program, it will occurs a
deadlock.

I discovered that the method Wait() of 'cond' calls the method RUnlock() of 'rwmutex '.
And, RUnlock() will do not release semaphore 'writerSem' when RLock() not be called
before this. But rwmutex.Lock() will acquires semaphore 'writerSem'. In this program, it
will make a deadlock. 

Although I not using 'cond' in the correct way designedly, but it does create some
sticky issue. That should be a BUG, right?

I look forward to the reply.
@dvyukov
Copy link
Member

dvyukov commented Apr 24, 2014

Comment 1:

What would you expect this buggy program to do (rather than deadlock)?

@ianlancetaylor
Copy link
Contributor

Comment 3:

If you use the sync functions and methods incorrectly, many things can go wrong.  The
package is designed to be efficient, not to make its best guess at what you are trying
to do.

Status changed to Invalid.

@dvyukov
Copy link
Member

dvyukov commented Apr 24, 2014

Comment 4:

Hold on, Ian.
Mutex detects Unlock w/o Lock and panics. I think we can do the same for RWMutex.
That's not to say that we can adequately react on all incorrect usages. But at least we
can do some best-effort detection.

Labels changed: added release-go1.4, repo-main.

Owner changed to @dvyukov.

Status changed to Accepted.

@dvyukov
Copy link
Member

dvyukov commented Apr 24, 2014

Comment 5:

I've prepared https://golang.org/cl/92720045 for Go1.4.
With that patch, the program crashes with:
panic: sync: RUnlock of unlocked RWMutex
goroutine 20 [running]:
sync.(*RWMutex).RUnlock(0x554850)
    src/pkg/sync/rwmutex.go:57 +0x103
sync.(*rlocker).Unlock(0x554850)
    src/pkg/sync/rwmutex.go:136 +0x27
main.func·001(0x0)
    test.go:33 +0x26d

@hyper0x
Copy link
Author

hyper0x commented Apr 25, 2014

Comment 6:

Thank you for your reply. I'm eager to see the result.

@dvyukov
Copy link
Member

dvyukov commented Apr 27, 2014

Comment 7:

Issue #7877 has been merged into this issue.

@gopherbot
Copy link

Comment 8:

CL https://golang.org/cl/92720045 mentions this issue.

@dvyukov
Copy link
Member

dvyukov commented Jun 20, 2014

Comment 9:

This issue was closed by revision 22d46d5.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants