Anonymous | Login | 2024-04-19 13:20 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000874 | [1003.1(2013)/Issue7+TC1] System Interfaces | Comment | Error | 2014-09-05 10:31 | 2019-06-10 08:54 | ||
Reporter | geoffclare | View Status | public | ||||
Assigned To | |||||||
Priority | normal | Resolution | Accepted As Marked | ||||
Status | Closed | ||||||
Name | Geoff Clare | ||||||
Organization | The Open Group | ||||||
User Reference | |||||||
Section | pthread_once() | ||||||
Page Number | 1685 | ||||||
Line Number | 54518 | ||||||
Interp Status | --- | ||||||
Final Accepted Text | Note: 0002417 | ||||||
Summary | 0000874: pthread_once() rationale makes bogus claims | ||||||
Description |
The following paragraph in the pthread_once() rationale makes bogus claims about the need for pthread_once():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. Ensuring that a mutex is only initialised once does not require a recursive solution. All it requires is: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 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: extern int initialize_random(); to: extern void initialize_random(void); 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 pthread_once() 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 pthread_once() as follows: |
||||||
Tags | tc2-2008 | ||||||
Attached Files | |||||||
|
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 | => --- |
2014-09-06 13:14 | dalias | Note Added: 0002375 | |
2014-10-09 16:20 | rhansen | Note Added: 0002417 | |
2014-10-09 16:21 | rhansen | Final Accepted Text | => Note: 0002417 |
2014-10-09 16:21 | rhansen | Status | New => Resolved |
2014-10-09 16:21 | rhansen | Resolution | Open => Accepted As Marked |
2014-10-09 16:22 | rhansen | Tag Attached: tc2-2008 | |
2019-06-10 08:54 | agadmin | Status | Resolved => Closed |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |