Closed
Description
Feature gate: #![feature(thread_local_const_init)]
This is a tracking issue for the const
-initialization of thread locals in the standard library added in #83416.
Public API
use std::cell::Cell;
std::thread_local!(static KEY: Cell<u32> = const { Cell::new(0) });
// ... same APIs as before with thread locals
The API here is intended to be exclusively within the syntax of the preexisting thread_local!
macro. The initialization expression for thread local keys can now be surrounded with const { ... }
to indicate that the value should be const-evaluated and initialized.
Note that this also supports the multi-definition form:
use std::cell::Cell;
std::thread_local! {
static KEY1: Cell<u32> = const { Cell::new(0) };
static KEY2: Cell<u32> = const { Cell::new(0) };
}
Steps / History
- Implementation: std: Add a variant of thread locals with const init #83416
- Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
- Syntax bikeshed - is the use of what is likely to be a future-feature,
const
blocks, ok here? Are there other options for syntax?
Metadata
Metadata
Assignees
Labels
Area: Thread local storage (TLS)Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the language team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.