UNSYNCHRONIZED does NOT unlock the mutex
authorShaft Wu <shaftwu@fb.com>
Wed, 11 Nov 2015 04:40:17 +0000 (20:40 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 11 Nov 2015 05:20:20 +0000 (21:20 -0800)
commit6762f08b48558f5afbdce1a435ab0e82deab837b
tree51fcbeac87c2ef0a77e1155af434730cdc9bd2a0
parent7ab42fa8f1e672d9c96e9516d84b1c1fb3f0546f
UNSYNCHRONIZED does NOT unlock the mutex

Summary: My colleague tuomaspelkonen discovered a weird UNSYNCHRONIZED issue a few weeks ago and we ever since stopped using it. Now I finally have some time to root cause it. It turns out UNSYNCHRONIZED unlock the mutex then lock the mutex again, because it copy constructs LockedPtr for overriding the name within the scope, and copy construct locks the mutex again. A one character fix here is to take a reference of LockedPtr instead of copy construct it. However since this is my first time look at the code here, please advise if this is horribly wrong or propose better fix. Also added a test to reproduce the issue without the fix as well as verify the fix.

Reviewed By: yfeldblum

Differential Revision: D2633028

fb-gh-sync-id: a9e8d39b08d4d1265979f8bdaae83619566d10a0
folly/Synchronized.h
folly/test/SynchronizedTest.cpp