Austin Group Bug Tracker
2014-09-05 10:31:54 UTC
The following issue has been SUBMITTED.
======================================================================
http://austingroupbugs.net/view.php?id=874
======================================================================
Reported By: geoffclare
Assigned To:
======================================================================
Project: 1003.1(2013)/Issue7+TC1
Issue ID: 874
Category: System Interfaces
Type: Error
Severity: Comment
Priority: normal
Status: New
Name: Geoff Clare
Organization: The Open Group
User Reference:
Section: pthread_once()
Page Number: 1685
Line Number: 54518
Interp Status: ---
Final Accepted Text:
======================================================================
Date Submitted: 2014-09-05 10:31 UTC
Last Modified: 2014-09-05 10:31 UTC
======================================================================
Summary: pthread_once() rationale makes bogus claims
Description:
The following paragraph in the pthread_once() rationale makes bogus claims
about the need for pthread_once():<blockquote>For dynamic library
initialization in a multi-threaded process, a simple initialization flag is
not sufficient; the flag needs to be protected against modification by
multiple threads simultaneously calling into the library. Protecting the
flag requires the use of a mutex; however, mutexes have to be initialized
before they are used. Ensuring that the mutex is only initialized once
requires a recursive solution to this problem.</blockquote>
Ensuring that a mutex is only initialised once does not require a recursive
solution. All it requires is:<pre>pthread_mutex_t mutex =
PTHREAD_MUTEX_INITIALIZER;</pre>
Also, "protecting the flag requires the use of a mutex" is not true, as
there are other ways that the flag could be protected.
In addition, there is a bug in the example code: the initialize_random()
function should have return type void, not int.
Desired Action:
On page 1684 line 54506 section pthread_once()
and page 1685 line 54528 section pthread_once()
In the RATIONALE section, change from:<pre>extern int
initialize_random();</pre>
to:<pre>extern void initialize_random(void);</pre>
On page 1685 line 54518 section pthread_once()
In the RATIONALE section, change from:
For dynamic library initialization in a multi-threaded process, a simple
initialization flag is not sufficient; the flag needs to be protected
against modification by multiple threads simultaneously calling into the
library. Protecting the flag requires the use of a mutex; however, mutexes
have to be initialized before they are used. Ensuring that the mutex is
only initialized once requires a recursive solution to this problem.
The use of <i>pthread_once</i>() not only supplies an
implementation-guaranteed means of dynamic initialization, it provides an
aid to the reliable construction of multi-threaded and realtime systems.
The preceding example then becomes:
to:
For dynamic library initialization in a multi-threaded process, if an
initialization flag is used the flag needs to be protected against
modification by multiple threads simultaneously calling into the library.
This can be done by using a mutex (initialized by assigning
PTHREAD_MUTEX_INITIALIZER). However, the need for a flag can be avoided
altogether by using <i>pthread_once</i>() as follows:
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2014-09-05 10:31 geoffclare New Issue
2014-09-05 10:31 geoffclare Name => Geoff Clare
2014-09-05 10:31 geoffclare Organization => The Open Group
2014-09-05 10:31 geoffclare Section => pthread_once()
2014-09-05 10:31 geoffclare Page Number => 1685
2014-09-05 10:31 geoffclare Line Number => 54518
2014-09-05 10:31 geoffclare Interp Status => ---
======================================================================
======================================================================
http://austingroupbugs.net/view.php?id=874
======================================================================
Reported By: geoffclare
Assigned To:
======================================================================
Project: 1003.1(2013)/Issue7+TC1
Issue ID: 874
Category: System Interfaces
Type: Error
Severity: Comment
Priority: normal
Status: New
Name: Geoff Clare
Organization: The Open Group
User Reference:
Section: pthread_once()
Page Number: 1685
Line Number: 54518
Interp Status: ---
Final Accepted Text:
======================================================================
Date Submitted: 2014-09-05 10:31 UTC
Last Modified: 2014-09-05 10:31 UTC
======================================================================
Summary: pthread_once() rationale makes bogus claims
Description:
The following paragraph in the pthread_once() rationale makes bogus claims
about the need for pthread_once():<blockquote>For dynamic library
initialization in a multi-threaded process, a simple initialization flag is
not sufficient; the flag needs to be protected against modification by
multiple threads simultaneously calling into the library. Protecting the
flag requires the use of a mutex; however, mutexes have to be initialized
before they are used. Ensuring that the mutex is only initialized once
requires a recursive solution to this problem.</blockquote>
Ensuring that a mutex is only initialised once does not require a recursive
solution. All it requires is:<pre>pthread_mutex_t mutex =
PTHREAD_MUTEX_INITIALIZER;</pre>
Also, "protecting the flag requires the use of a mutex" is not true, as
there are other ways that the flag could be protected.
In addition, there is a bug in the example code: the initialize_random()
function should have return type void, not int.
Desired Action:
On page 1684 line 54506 section pthread_once()
and page 1685 line 54528 section pthread_once()
In the RATIONALE section, change from:<pre>extern int
initialize_random();</pre>
to:<pre>extern void initialize_random(void);</pre>
On page 1685 line 54518 section pthread_once()
In the RATIONALE section, change from:
For dynamic library initialization in a multi-threaded process, a simple
initialization flag is not sufficient; the flag needs to be protected
against modification by multiple threads simultaneously calling into the
library. Protecting the flag requires the use of a mutex; however, mutexes
have to be initialized before they are used. Ensuring that the mutex is
only initialized once requires a recursive solution to this problem.
The use of <i>pthread_once</i>() not only supplies an
implementation-guaranteed means of dynamic initialization, it provides an
aid to the reliable construction of multi-threaded and realtime systems.
The preceding example then becomes:
to:
For dynamic library initialization in a multi-threaded process, if an
initialization flag is used the flag needs to be protected against
modification by multiple threads simultaneously calling into the library.
This can be done by using a mutex (initialized by assigning
PTHREAD_MUTEX_INITIALIZER). However, the need for a flag can be avoided
altogether by using <i>pthread_once</i>() as follows:
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2014-09-05 10:31 geoffclare New Issue
2014-09-05 10:31 geoffclare Name => Geoff Clare
2014-09-05 10:31 geoffclare Organization => The Open Group
2014-09-05 10:31 geoffclare Section => pthread_once()
2014-09-05 10:31 geoffclare Page Number => 1685
2014-09-05 10:31 geoffclare Line Number => 54518
2014-09-05 10:31 geoffclare Interp Status => ---
======================================================================