| 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];
|
| + }
|
| +}
|
|
|