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-23 15:57 | 
| Reporter | elahav | Assigned To | |||
| Priority | normal | Severity | Editorial | Type | Enhancement Request | 
| Status | Closed | Resolution | Rejected | ||
| 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. | ||||
|  | While the idea may have merit, the Austin Group is required to consider existing implementations in the standardization process. We advise attempting to get at least one existing libc implementation to implement the proposal, possibly under a slightly different name like pthread_create_detached_np to minimize issues with future namespace changes, at which point it will be easier to augment POSIX to standardize the interface if a sponsor for the new interface is found. For now, this issue is being rejected for lack of implementation practice. | 
