Chromium Code Reviews| Index: test/cctest/test-threads.cc |
| diff --git a/test/cctest/test-threads.cc b/test/cctest/test-threads.cc |
| index 37f020509cefca3378f07467e6d237caeb77c850..2e1c0732be92c3f59c098aa8171ce3df1fbd9377 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, |
|
Vitaly Repeshko
2011/04/11 19:28:52
Non-const references are prohibited in parameters
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| + unsigned int nThread, |
|
Vitaly Repeshko
2011/04/11 19:28:52
noCamelCaseOrHungaryPlease! use_std_lib_style_for_
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| + i::Semaphore* semaphore) |
| + : Thread(NULL, "ThreadRefValidationThread"), |
| + refs_(refs), nThread_(nThread), thread_to_start_(thread_to_start), |
| + semaphore_(semaphore) { |
| + } |
| + |
| + void Run() { |
| + i::ThreadId thread_id = i::ThreadId::Current(); |
| + for (int i = 0; i < nThread_; i++) { |
| + CHECK(!refs_[i].Equals(thread_id)); |
| + } |
| + CHECK(!thread_id.Equals(i::ThreadId::Invalid())); |
| + refs_[nThread_] = thread_id; |
| + if (thread_to_start_ != NULL) { |
| + thread_to_start_->Start(); |
| + } |
| + semaphore_->Signal(); |
| +} |
|
Vitaly Repeshko
2011/04/11 19:28:52
Weird indentation.
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| + private: |
| + i::List<i::ThreadId>& refs_; |
| + int nThread_; |
| + 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]; |
|
Vitaly Repeshko
2011/04/11 19:28:52
Should we join a thread before deleting it?
Dmitry Lomov
2011/04/11 20:08:35
NO! We must not. Thread::Join relies on pthread_t
|
| + } |
| +} |