diff options
author | Elliott Hughes <enh@google.com> | 2011-10-06 13:53:01 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-10-06 13:59:40 -0700 |
commit | 3b3e118262c4717ef367e73445442e640f4093d8 (patch) | |
tree | aea80a1c9da052168144de89c0af988f6833f30c | |
parent | 32caed449e4f2ecd90ebb116a714df0ebcc537e9 (diff) | |
download | art-3b3e118262c4717ef367e73445442e640f4093d8.zip art-3b3e118262c4717ef367e73445442e640f4093d8.tar.gz art-3b3e118262c4717ef367e73445442e640f4093d8.tar.bz2 |
Fix the thread test to not be racy.
We shouldn't assume we know what order threads will be started in.
Running a debug build, it sometimes takes > 1ms to start the next
thread.
Change-Id: Icb7792f83809ad414cfcdf0828cdc198698deaf1
-rw-r--r-- | test/051-thread/expected.txt | 513 | ||||
-rw-r--r-- | test/051-thread/src/Main.java | 28 |
2 files changed, 19 insertions, 522 deletions
diff --git a/test/051-thread/expected.txt b/test/051-thread/expected.txt index 5370049..8e6b153 100644 --- a/test/051-thread/expected.txt +++ b/test/051-thread/expected.txt @@ -1,516 +1,5 @@ Initializing System.out... -running 0 -running 1 -running 2 -running 3 -running 4 -running 5 -running 6 -running 7 -running 8 -running 9 -running 10 -running 11 -running 12 -running 13 -running 14 -running 15 -running 16 -running 17 -running 18 -running 19 -running 20 -running 21 -running 22 -running 23 -running 24 -running 25 -running 26 -running 27 -running 28 -running 29 -running 30 -running 31 -running 32 -running 33 -running 34 -running 35 -running 36 -running 37 -running 38 -running 39 -running 40 -running 41 -running 42 -running 43 -running 44 -running 45 -running 46 -running 47 -running 48 -running 49 -running 50 -running 51 -running 52 -running 53 -running 54 -running 55 -running 56 -running 57 -running 58 -running 59 -running 60 -running 61 -running 62 -running 63 -running 64 -running 65 -running 66 -running 67 -running 68 -running 69 -running 70 -running 71 -running 72 -running 73 -running 74 -running 75 -running 76 -running 77 -running 78 -running 79 -running 80 -running 81 -running 82 -running 83 -running 84 -running 85 -running 86 -running 87 -running 88 -running 89 -running 90 -running 91 -running 92 -running 93 -running 94 -running 95 -running 96 -running 97 -running 98 -running 99 -running 100 -running 101 -running 102 -running 103 -running 104 -running 105 -running 106 -running 107 -running 108 -running 109 -running 110 -running 111 -running 112 -running 113 -running 114 -running 115 -running 116 -running 117 -running 118 -running 119 -running 120 -running 121 -running 122 -running 123 -running 124 -running 125 -running 126 -running 127 -running 128 -running 129 -running 130 -running 131 -running 132 -running 133 -running 134 -running 135 -running 136 -running 137 -running 138 -running 139 -running 140 -running 141 -running 142 -running 143 -running 144 -running 145 -running 146 -running 147 -running 148 -running 149 -running 150 -running 151 -running 152 -running 153 -running 154 -running 155 -running 156 -running 157 -running 158 -running 159 -running 160 -running 161 -running 162 -running 163 -running 164 -running 165 -running 166 -running 167 -running 168 -running 169 -running 170 -running 171 -running 172 -running 173 -running 174 -running 175 -running 176 -running 177 -running 178 -running 179 -running 180 -running 181 -running 182 -running 183 -running 184 -running 185 -running 186 -running 187 -running 188 -running 189 -running 190 -running 191 -running 192 -running 193 -running 194 -running 195 -running 196 -running 197 -running 198 -running 199 -running 200 -running 201 -running 202 -running 203 -running 204 -running 205 -running 206 -running 207 -running 208 -running 209 -running 210 -running 211 -running 212 -running 213 -running 214 -running 215 -running 216 -running 217 -running 218 -running 219 -running 220 -running 221 -running 222 -running 223 -running 224 -running 225 -running 226 -running 227 -running 228 -running 229 -running 230 -running 231 -running 232 -running 233 -running 234 -running 235 -running 236 -running 237 -running 238 -running 239 -running 240 -running 241 -running 242 -running 243 -running 244 -running 245 -running 246 -running 247 -running 248 -running 249 -running 250 -running 251 -running 252 -running 253 -running 254 -running 255 -running 256 -running 257 -running 258 -running 259 -running 260 -running 261 -running 262 -running 263 -running 264 -running 265 -running 266 -running 267 -running 268 -running 269 -running 270 -running 271 -running 272 -running 273 -running 274 -running 275 -running 276 -running 277 -running 278 -running 279 -running 280 -running 281 -running 282 -running 283 -running 284 -running 285 -running 286 -running 287 -running 288 -running 289 -running 290 -running 291 -running 292 -running 293 -running 294 -running 295 -running 296 -running 297 -running 298 -running 299 -running 300 -running 301 -running 302 -running 303 -running 304 -running 305 -running 306 -running 307 -running 308 -running 309 -running 310 -running 311 -running 312 -running 313 -running 314 -running 315 -running 316 -running 317 -running 318 -running 319 -running 320 -running 321 -running 322 -running 323 -running 324 -running 325 -running 326 -running 327 -running 328 -running 329 -running 330 -running 331 -running 332 -running 333 -running 334 -running 335 -running 336 -running 337 -running 338 -running 339 -running 340 -running 341 -running 342 -running 343 -running 344 -running 345 -running 346 -running 347 -running 348 -running 349 -running 350 -running 351 -running 352 -running 353 -running 354 -running 355 -running 356 -running 357 -running 358 -running 359 -running 360 -running 361 -running 362 -running 363 -running 364 -running 365 -running 366 -running 367 -running 368 -running 369 -running 370 -running 371 -running 372 -running 373 -running 374 -running 375 -running 376 -running 377 -running 378 -running 379 -running 380 -running 381 -running 382 -running 383 -running 384 -running 385 -running 386 -running 387 -running 388 -running 389 -running 390 -running 391 -running 392 -running 393 -running 394 -running 395 -running 396 -running 397 -running 398 -running 399 -running 400 -running 401 -running 402 -running 403 -running 404 -running 405 -running 406 -running 407 -running 408 -running 409 -running 410 -running 411 -running 412 -running 413 -running 414 -running 415 -running 416 -running 417 -running 418 -running 419 -running 420 -running 421 -running 422 -running 423 -running 424 -running 425 -running 426 -running 427 -running 428 -running 429 -running 430 -running 431 -running 432 -running 433 -running 434 -running 435 -running 436 -running 437 -running 438 -running 439 -running 440 -running 441 -running 442 -running 443 -running 444 -running 445 -running 446 -running 447 -running 448 -running 449 -running 450 -running 451 -running 452 -running 453 -running 454 -running 455 -running 456 -running 457 -running 458 -running 459 -running 460 -running 461 -running 462 -running 463 -running 464 -running 465 -running 466 -running 467 -running 468 -running 469 -running 470 -running 471 -running 472 -running 473 -running 474 -running 475 -running 476 -running 477 -running 478 -running 479 -running 480 -running 481 -running 482 -running 483 -running 484 -running 485 -running 486 -running 487 -running 488 -running 489 -running 490 -running 491 -running 492 -running 493 -running 494 -running 495 -running 496 -running 497 -running 498 -running 499 -running 500 -running 501 -running 502 -running 503 -running 504 -running 505 -running 506 -running 507 -running 508 -running 509 -running 510 -running 511 +Thread count: 512 Starting thread 'Thready' @ Thread running @ Got expected setDaemon exception diff --git a/test/051-thread/src/Main.java b/test/051-thread/src/Main.java index 7cc3db4..95ec1a1 100644 --- a/test/051-thread/src/Main.java +++ b/test/051-thread/src/Main.java @@ -1,22 +1,28 @@ // Copyright 2006 The Android Open Source Project +import java.util.ArrayList; + /** * Test some basic thread stuff. */ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws Exception { System.out.println("Initializing System.out..."); + MyThread[] threads = new MyThread[512]; for (int i = 0; i < 512; i++) { - MyThread myThread = new MyThread(); - myThread.start(); - try { - Thread.sleep(1); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } + threads[i] = new MyThread(); } + for (MyThread thread : threads) { + thread.start(); + } + for (MyThread thread : threads) { + thread.join(); + } + + System.out.println("Thread count: " + MyThread.mCount); + go(); System.out.println("thread test done"); } @@ -42,9 +48,11 @@ public class Main { * Simple thread capacity test. */ static class MyThread extends Thread { - private static int mCount = 0; + static int mCount = 0; public void run() { - System.out.println("running " + (mCount++)); + synchronized (MyThread.class) { + ++mCount; + } } } } |