thread-safe:线程安全的;指在多线程环境下,某段代码、数据结构或对象即使被多个线程同时访问/修改,也能保持结果正确、状态一致,不会产生竞态条件等并发错误。(也可写作 thread safe)
/ˈθrɛd ˌseɪf/
This class is thread-safe.
这个类是线程安全的。
To avoid subtle bugs, the library uses thread-safe queues so multiple worker threads can process tasks concurrently without corrupting shared data.
为避免隐蔽的错误,这个库使用线程安全的队列,让多个工作线程能并发处理任务而不破坏共享数据。
由 thread(线程) + safe(安全的) 组合而成,是计算机领域的常用术语。随着多核处理器与并发编程普及,“thread-safe”用于强调某实现具备在并发访问下仍能保持正确性的设计(常借助锁、原子操作、不可变对象或无锁算法等)。