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

Unified Diff: test/cctest/test-threads.cc

Issue 6816038: Do not rely on uniquiness of pthread_t Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Win32 build fix Created 9 years, 8 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 | « src/v8threads.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-threads.cc
diff --git a/test/cctest/test-threads.cc b/test/cctest/test-threads.cc
index 37f020509cefca3378f07467e6d237caeb77c850..c6d5cb09a08b4c7f3a8ee110e1d1ed84d87c01aa 100644
--- a/test/cctest/test-threads.cc
+++ b/test/cctest/test-threads.cc
@@ -28,6 +28,7 @@
#include "v8.h"
#include "platform.h"
+#include "isolate.h"
#include "cctest.h"
@@ -136,3 +137,55 @@ TEST(JSFunctionResultCachesInTwoThreads) {
CHECK_EQ(DONE, turn);
}
+
+class ThreadIdValidationThread : public v8::internal::Thread {
+ public:
+ ThreadIdValidationThread(i::Thread* thread_to_start,
+ i::List<i::ThreadId>* refs,
+ unsigned int thread_no,
+ i::Semaphore* semaphore)
+ : Thread(NULL, "ThreadRefValidationThread"),
+ refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start),
+ semaphore_(semaphore) {
+ }
+
+ void Run() {
+ i::ThreadId thread_id = i::ThreadId::Current();
+ for (int i = 0; i < thread_no_; i++) {
+ CHECK(!(*refs_)[i].Equals(thread_id));
+ }
+ CHECK(thread_id.IsValid());
+ (*refs_)[thread_no_] = thread_id;
+ if (thread_to_start_ != NULL) {
+ thread_to_start_->Start();
+ }
+ semaphore_->Signal();
+ }
+ private:
+ i::List<i::ThreadId>* refs_;
+ int thread_no_;
+ i::Thread* thread_to_start_;
+ i::Semaphore* semaphore_;
+};
+
+TEST(ThreadIdValidation) {
+ const int kNThreads = 100;
+ i::List<ThreadIdValidationThread*> threads(kNThreads);
+ i::List<i::ThreadId> refs(kNThreads);
+ i::Semaphore* semaphore = i::OS::CreateSemaphore(0);
+ ThreadIdValidationThread* prev = NULL;
+ for (int i = kNThreads - 1; i >= 0; i--) {
+ ThreadIdValidationThread* newThread =
+ new ThreadIdValidationThread(prev, &refs, i, semaphore);
+ threads.Add(newThread);
+ prev = newThread;
+ refs.Add(i::ThreadId::Invalid());
+ }
+ prev->Start();
+ for (int i = 0; i < kNThreads; i++) {
+ semaphore->Wait();
+ }
+ for (int i = 0; i < kNThreads; i++) {
+ delete threads[i];
+ }
+}
« no previous file with comments | « src/v8threads.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698