Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1044)

Side by Side Diff: runtime/vm/thread_barrier_test.cc

Issue 1337943004: Add ThreadBarrier; use in GCMarker and unit test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix git again. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/thread_barrier.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/assert.h"
6 #include "vm/random.h"
7 #include "vm/thread_barrier.h"
8 #include "vm/thread_pool.h"
9 #include "vm/unit_test.h"
10
11 namespace dart {
12
13 class FuzzTask : public ThreadPool::Task {
14 public:
15 FuzzTask(intptr_t num_rounds,
16 ThreadBarrier* barrier,
17 uint64_t seed)
18 : num_rounds_(num_rounds),
19 barrier_(barrier),
20 rng_(seed) {
21 }
22
23 virtual void Run() {
24 for (intptr_t i = 0; i < num_rounds_; ++i) {
25 RandomSleep();
26 barrier_->Sync();
27 }
28 barrier_->Exit();
29 }
30
31 private:
32 void RandomSleep() {
33 int64_t ms = rng_.NextUInt32() % 4;
34 if (ms > 0) {
35 OS::Sleep(ms);
36 }
37 }
38
39 const intptr_t num_rounds_;
40 ThreadBarrier* barrier_;
41 Random rng_;
42 };
43
44
45 UNIT_TEST_CASE(ThreadBarrier) {
46 static const intptr_t kNumTasks = 5;
47 static const intptr_t kNumRounds = 500;
48
49 ThreadBarrier barrier(kNumTasks + 1);
50 for (intptr_t i = 0; i < kNumTasks; ++i) {
51 Dart::thread_pool()->Run(new FuzzTask(kNumRounds, &barrier, i + 1));
52 }
53 for (intptr_t i = 0; i < kNumRounds; ++i) {
54 barrier.Sync();
55 }
56 barrier.Exit();
57 }
58
59 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread_barrier.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698