View Issue Details

IDProjectCategoryView StatusLast Update
00019501003.1(2024)/Issue8System Interfacespublic2025-10-10 22:50
Reporterelahav Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status NewResolutionOpen 
NameElad Lahav
OrganizationBlackBerry QNX
User Reference
SectionSystem Interfaces
Page NumberN/A
Line NumberN/A
Interp Status
Final Accepted Text
Summary0001950: Create a detached thread with a function that returns void
DescriptionIt 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 ActionProposing 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.
TagsNo tags attached.

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2025-10-10 22:50 elahav New Issue