View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001950 | 1003.1(2024)/Issue8 | System Interfaces | public | 2025-10-10 22:50 | 2025-10-10 22:50 |
Reporter | elahav | Assigned To | |||
Priority | normal | Severity | Editorial | Type | Enhancement Request |
Status | New | Resolution | Open | ||
Name | Elad Lahav | ||||
Organization | BlackBerry QNX | ||||
User Reference | |||||
Section | System Interfaces | ||||
Page Number | N/A | ||||
Line Number | N/A | ||||
Interp Status | |||||
Final Accepted Text | |||||
Summary | 0001950: Create a detached thread with a function that returns void | ||||
Description | It is a fairly common pattern (especially in embedded systems) to create a thread that runs an infinite loop, with option to return. Such a thread can be created as detached (PTHREAD_CREATE_DETACHED), as there is no reason to call pthread_join() on a thread that doesn't return. The problem is that pthread_create() takes a function that returns void*. This causes problems with several standards, such as ISO C and MISRA: void *thread_func(void *arg) { for (;;) { ... } } The function must return a value, but cannot have a return statement after (or within) the for loop, as that would be dead code. The function cannot be marked as no-return, because of its type. If the type is changed to void, the function cannot be passed to pthread_create() without illegal (according to the standard) casts. | ||||
Desired Action | Proposing a new function int pthread_create_detached(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void (*start_routine)(void*), void *restrict arg); The function is identical to pthread_create(), except for the start_routine signature, and that it always sets the PTHREAD_CREATE_DETACHED attribute. | ||||
Tags | No tags attached. |
Date Modified | Username | Field | Change |
---|---|---|---|
2025-10-10 22:50 | elahav | New Issue |