1
+ #![ cfg_attr( unstable_channel, feature( scoped_threads) ) ]
1
2
#![ deny( rust_2018_compatibility) ]
2
3
#![ deny( rust_2018_idioms) ]
3
4
#![ deny( warnings) ]
4
5
5
- use std:: { sync :: mpsc , thread} ;
6
+ use std:: thread;
6
7
7
- use heapless:: { mpmc:: Q64 , spsc} ;
8
- use scoped_threadpool:: Pool ;
8
+ use heapless:: spsc;
9
9
10
10
#[ test]
11
11
fn once ( ) {
@@ -51,6 +51,7 @@ fn twice() {
51
51
}
52
52
53
53
#[ test]
54
+ #[ cfg( unstable_channel) ]
54
55
fn scoped ( ) {
55
56
let mut rb: spsc:: Queue < i32 , 5 > = spsc:: Queue :: new ( ) ;
56
57
@@ -59,12 +60,12 @@ fn scoped() {
59
60
{
60
61
let ( mut p, mut c) = rb. split ( ) ;
61
62
62
- Pool :: new ( 2 ) . scoped ( move |scope| {
63
- scope. execute ( move || {
63
+ thread :: scope ( move |scope| {
64
+ scope. spawn ( move || {
64
65
p. enqueue ( 1 ) . unwrap ( ) ;
65
66
} ) ;
66
67
67
- scope. execute ( move || {
68
+ scope. spawn ( move || {
68
69
c. dequeue ( ) . unwrap ( ) ;
69
70
} ) ;
70
71
} ) ;
@@ -75,6 +76,7 @@ fn scoped() {
75
76
76
77
#[ test]
77
78
#[ cfg_attr( miri, ignore) ] // too slow
79
+ #[ cfg( unstable_channel) ]
78
80
fn contention ( ) {
79
81
const N : usize = 1024 ;
80
82
@@ -83,8 +85,8 @@ fn contention() {
83
85
{
84
86
let ( mut p, mut c) = rb. split ( ) ;
85
87
86
- Pool :: new ( 2 ) . scoped ( move |scope| {
87
- scope. execute ( move || {
88
+ thread :: scope ( move |scope| {
89
+ scope. spawn ( move || {
88
90
let mut sum: u32 = 0 ;
89
91
90
92
for i in 0 ..( 2 * N ) {
@@ -95,7 +97,7 @@ fn contention() {
95
97
println ! ( "producer: {}" , sum) ;
96
98
} ) ;
97
99
98
- scope. execute ( move || {
100
+ scope. spawn ( move || {
99
101
let mut sum: u32 = 0 ;
100
102
101
103
for _ in 0 ..( 2 * N ) {
@@ -120,15 +122,20 @@ fn contention() {
120
122
121
123
#[ test]
122
124
#[ cfg_attr( miri, ignore) ] // too slow
125
+ #[ cfg( unstable_channel) ]
123
126
fn mpmc_contention ( ) {
127
+ use std:: sync:: mpsc;
128
+
129
+ use heapless:: mpmc:: Q64 ;
130
+
124
131
const N : u32 = 64 ;
125
132
126
133
static Q : Q64 < u32 > = Q64 :: new ( ) ;
127
134
128
135
let ( s, r) = mpsc:: channel ( ) ;
129
- Pool :: new ( 2 ) . scoped ( |scope| {
136
+ thread :: scope ( |scope| {
130
137
let s1 = s. clone ( ) ;
131
- scope. execute ( move || {
138
+ scope. spawn ( move || {
132
139
let mut sum: u32 = 0 ;
133
140
134
141
for i in 0 ..( 16 * N ) {
@@ -141,7 +148,7 @@ fn mpmc_contention() {
141
148
} ) ;
142
149
143
150
let s2 = s. clone ( ) ;
144
- scope. execute ( move || {
151
+ scope. spawn ( move || {
145
152
let mut sum: u32 = 0 ;
146
153
147
154
for _ in 0 ..( 16 * N ) {
@@ -166,6 +173,7 @@ fn mpmc_contention() {
166
173
167
174
#[ test]
168
175
#[ cfg_attr( miri, ignore) ] // too slow
176
+ #[ cfg( unstable_channel) ]
169
177
fn unchecked ( ) {
170
178
const N : usize = 1024 ;
171
179
@@ -178,14 +186,14 @@ fn unchecked() {
178
186
{
179
187
let ( mut p, mut c) = rb. split ( ) ;
180
188
181
- Pool :: new ( 2 ) . scoped ( move |scope| {
182
- scope. execute ( move || {
189
+ thread :: scope ( move |scope| {
190
+ scope. spawn ( move || {
183
191
for _ in 0 ..N / 2 - 1 {
184
192
p. enqueue ( 2 ) . unwrap ( ) ;
185
193
}
186
194
} ) ;
187
195
188
- scope. execute ( move || {
196
+ scope. spawn ( move || {
189
197
let mut sum: usize = 0 ;
190
198
191
199
for _ in 0 ..N / 2 - 1 {
@@ -246,8 +254,8 @@ fn pool() {
246
254
247
255
A :: grow ( unsafe { & mut M } ) ;
248
256
249
- Pool :: new ( 2 ) . scoped ( move |scope| {
250
- scope. execute ( move || {
257
+ thread :: scope ( move |scope| {
258
+ scope. spawn ( move || {
251
259
for _ in 0 ..N / 4 {
252
260
let a = A :: alloc ( ) . unwrap ( ) ;
253
261
let b = A :: alloc ( ) . unwrap ( ) ;
@@ -257,7 +265,7 @@ fn pool() {
257
265
}
258
266
} ) ;
259
267
260
- scope. execute ( move || {
268
+ scope. spawn ( move || {
261
269
for _ in 0 ..N / 2 {
262
270
let a = A :: alloc ( ) . unwrap ( ) ;
263
271
let a = a. init ( [ 2 ; 8 ] ) ;
0 commit comments