Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Alexander Terekhov Newsgroups: comp.std.c++ Subject: Re: mutexes try_lock noexcept issue Date: Wed, 11 Jan 2012 09:58:58 -0800 (PST) Organization: A noiseless patient Spider Lines: 58 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: <4F0C89DE.EC72DEB3@web.de> References: <2012010311540476770-pete@versatilecodingcom> Reply-To: terekhov@web.de NNTP-Posting-Host: Nee2L9t02DsdnibwKC+LN2lVuLGCMKBLnlwGMQ5f7dI= Content-Type: text/plain; charset=us-ascii X-Trace: news.albasani.net IaBcxMI4m3VORhgO4jjqqgtT1nyZNo2ZloK4O3ntIXv78usc8bq3H2EtgJJ5/SBjYOrczeR1gm6S6bP9qhtO0A== X-Complaints-To: abuse@albasani.net NNTP-Posting-Date: Wed, 11 Jan 2012 18:00:27 +0000 (UTC) X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:1WujBfTezplrilg1TU47jZjW7XA= X-Original-Date: Tue, 10 Jan 2012 19:56:30 +0100 Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:407 [ Moderator's note: The posting 'bot was down for a few days. -sdc ] Pete Becker wrote: > > On 2012-01-01 22:26:47 +0000, viboes said: > > > In 30.4.1.2.2 Class recursive_mutex [thread.mutex.recursive] > > > > try_lock is declared as noexcept > > > > bool try_lock() noexcept; > > > > but 30.4.1.2.1 Class mutex declare it without noexcept > > bool try_lock(); > > > > The same applies for timed_mutex and recursive_timed_mutex. > > > > Shouldn't both be coherent. When could try_lock throw an exception? > > > > If the mutex is already owned by the calling thread, the behavior of a > call to try_lock() is undefined. One possibility is to throw an > exception. For a recursive mutex, the behavior is well defined. http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html "ERRORS The pthread_mutex_lock() and pthread_mutex_trylock() functions shall fail if: [EAGAIN] The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded." How is that error is supposed to be reported with bool try_lock() noexcept given that false bool reflects "The pthread_mutex_trylock() function shall fail if: [EBUSY] The mutex could not be acquired because it was already locked. " regards, alexander. -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]