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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/thread_barrier.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_barrier_test.cc
diff --git a/runtime/vm/thread_barrier_test.cc b/runtime/vm/thread_barrier_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4517e18d95766079341f680224e62207bd4b1d14
--- /dev/null
+++ b/runtime/vm/thread_barrier_test.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/assert.h"
+#include "vm/random.h"
+#include "vm/thread_barrier.h"
+#include "vm/thread_pool.h"
+#include "vm/unit_test.h"
+
+namespace dart {
+
+class FuzzTask : public ThreadPool::Task {
+ public:
+ FuzzTask(intptr_t num_rounds,
+ ThreadBarrier* barrier,
+ uint64_t seed)
+ : num_rounds_(num_rounds),
+ barrier_(barrier),
+ rng_(seed) {
+ }
+
+ virtual void Run() {
+ for (intptr_t i = 0; i < num_rounds_; ++i) {
+ RandomSleep();
+ barrier_->Sync();
+ }
+ barrier_->Exit();
+ }
+
+ private:
+ void RandomSleep() {
+ int64_t ms = rng_.NextUInt32() % 4;
+ if (ms > 0) {
+ OS::Sleep(ms);
+ }
+ }
+
+ const intptr_t num_rounds_;
+ ThreadBarrier* barrier_;
+ Random rng_;
+};
+
+
+UNIT_TEST_CASE(ThreadBarrier) {
+ static const intptr_t kNumTasks = 5;
+ static const intptr_t kNumRounds = 500;
+
+ ThreadBarrier barrier(kNumTasks + 1);
+ for (intptr_t i = 0; i < kNumTasks; ++i) {
+ Dart::thread_pool()->Run(new FuzzTask(kNumRounds, &barrier, i + 1));
+ }
+ for (intptr_t i = 0; i < kNumRounds; ++i) {
+ barrier.Sync();
+ }
+ barrier.Exit();
+}
+
+} // namespace dart
« 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