@@ -12,7 +12,7 @@ struct Local(i32);
1212scoped_thread_local ! ( static LOCAL : Local ) ;
1313
1414#[ test]
15- fn scoped_tls_missing ( ) {
15+ fn missing_scoped_tls ( ) {
1616 LOCAL . set ( & Local ( 42 ) , || {
1717 let pool = ThreadPoolBuilder :: new ( )
1818 . build ( )
@@ -26,7 +26,7 @@ fn scoped_tls_missing() {
2626}
2727
2828#[ test]
29- fn scoped_tls_threadpool ( ) {
29+ fn spawn_scoped_tls_threadpool ( ) {
3030 LOCAL . set ( & Local ( 42 ) , || {
3131 LOCAL . with ( |x| {
3232 crossbeam:: scope ( |scope| {
@@ -64,3 +64,36 @@ fn scoped_tls_threadpool() {
6464 } ) ;
6565 } ) ;
6666}
67+
68+ #[ test]
69+ fn build_scoped_tls_threadpool ( ) {
70+ LOCAL . set ( & Local ( 42 ) , || {
71+ LOCAL . with ( |x| {
72+ ThreadPoolBuilder :: new ( )
73+ . build_scoped (
74+ move |thread| LOCAL . set ( x, || thread. run ( ) ) ,
75+ |pool| {
76+ // The pool matches our local value.
77+ pool. install ( || {
78+ assert ! ( LOCAL . is_set( ) ) ;
79+ LOCAL . with ( |y| {
80+ assert_eq ! ( x, y) ;
81+ } ) ;
82+ } ) ;
83+
84+ // If we change our local value, the pool is not affected.
85+ LOCAL . set ( & Local ( -1 ) , || {
86+ pool. install ( || {
87+ assert ! ( LOCAL . is_set( ) ) ;
88+ LOCAL . with ( |y| {
89+ assert_eq ! ( x, y) ;
90+ } ) ;
91+ } ) ;
92+ } ) ;
93+ } ,
94+ )
95+ . expect ( "thread pool created" ) ;
96+ // Internally, `crossbeam::scope` will wait for the threads to exit before returning.
97+ } ) ;
98+ } ) ;
99+ }
0 commit comments