pthread: facilitate dynamically allocated thread stacks
This change allows users to call pthread_create() with the pthread_attr_t argument equal to NULL. If Zephyr is configured with `CONFIG_DYNAMIC_THREAD`, then a suitable thread stack will be allocated via k_thread_stack_alloc(). The allocated thread stack is automatically freed via k_thread_stack_free(). This makes the Zephyr implementation of pthread_create() compliant with the normative spec. Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This commit is contained in:
parent
d7119b889f
commit
115efa2e35
3 changed files with 115 additions and 29 deletions
|
@ -7,3 +7,24 @@ TYPE = PTHREAD
|
|||
type = pthread_t
|
||||
type-function = pthread_create
|
||||
source "lib/posix/Kconfig.template.pooled_ipc_type"
|
||||
|
||||
if PTHREAD
|
||||
|
||||
config PTHREAD_RECYCLER_DELAY_MS
|
||||
int "Delay for reclaiming dynamic pthread stacks (ms)"
|
||||
default 100
|
||||
help
|
||||
Prior to a POSIX thread terminating via k_thread_abort(), scheduled
|
||||
work is added to the system workqueue (SWQ) so that any resources
|
||||
allocated by the thread (e.g. thread stack from a pool or the heap)
|
||||
can be released back to the system. Because resources are also freed
|
||||
on calls to pthread_create() there is no need to worry about resource
|
||||
starvation.
|
||||
|
||||
This option sets the number of milliseconds by which to defer
|
||||
scheduled work.
|
||||
|
||||
Note: this option should be considered temporary and will likely be
|
||||
removed once a more synchronous solution is available.
|
||||
|
||||
endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue