Home Dashboard Directory Help
Search

Compiler error on <mutex>:304 by Jorge.Ferreira


Status: 

Closed
 as Fixed Help for as Fixed


2
0
Sign in
to vote
Type: Bug
ID: 733222
Opened: 3/25/2012 2:36:21 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

A compiler error:

1>c:\program files\microsoft visual studio 11.0\vc\include\mutex(304): error C4716: 'std::unique_lock<std::mutex>::try_lock' : must return a value

occurs when compiling the following program:

#include "stdafx.h"
#include <mutex>

std::mutex m;

int _tmain(int argc, _TCHAR* argv[])
{
    std::unique_lock<std::mutex> lock_a(m, std::defer_lock);
    lock_a.try_lock();
    return 0;
}

The try_lock method of std::unique_lock must return a value. A possible fix would be:

bool try_lock() _NOEXCEPT
{    // try to lock the mutex
    _Owns = _Pmtx->try_lock();
    return (_Owns);
}
Details
Sign in to post a comment.
Posted by Microsoft on 3/26/2012 at 3:49 PM
Hi,

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VC11.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator09 [Feedback Moderator] on 3/25/2012 at 11:45 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 3/25/2012 at 2:46 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Jorge.Ferreira on 3/25/2012 at 2:39 PM
Edit <mutex> file (with administrator priveliges) and change the method try_lock of unique_lock (around line 304) to:

bool try_lock() _NOEXCEPT
{    // try to lock the mutex
    _Owns = _Pmtx->try_lock();
    return (_Owns);
}

Save the file and confirm that you want to overwrite it. The confirmation is necessary because the file may be read-only.