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

Side by Side Diff: base/threading/worker_pool_posix_unittest.cc

Issue 9281011: [Mac] In PlatformThread::CurrentId(), use pthread_self() instead of mach_thread_self(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/worker_pool_posix.h" 5 #include "base/threading/worker_pool_posix.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 while (peer_.num_idle_threads() > 0) { 224 while (peer_.num_idle_threads() > 0) {
225 peer_.pending_tasks_available_cv()->Signal(); 225 peer_.pending_tasks_available_cv()->Signal();
226 peer_.num_idle_threads_cv()->Wait(); 226 peer_.num_idle_threads_cv()->Wait();
227 } 227 }
228 } 228 }
229 229
230 // Add another non blocking task. There are no threads to reuse. 230 // Add another non blocking task. There are no threads to reuse.
231 pool_->PostTask(FROM_HERE, CreateNewIncrementingTaskCallback()); 231 pool_->PostTask(FROM_HERE, CreateNewIncrementingTaskCallback());
232 WaitForIdleThreads(1); 232 WaitForIdleThreads(1);
233 233
234 EXPECT_EQ(3U, unique_threads_.size()); 234 // The POSIX implementation of PlatformThread::CurrentId() uses pthread_self()
235 // which is not guaranteed to be unique after a thread joins. The OS X
236 // implemntation of pthread_self() returns the address of the pthread_t, which
237 // is merely a malloc()ed pointer stored in the first TLS slot. When a thread
238 // joins and that structure is freed, the block of memory can be put on the
239 // OS free list, meaning the same address could be reused in a subsequent
240 // allocation. This in fact happens when allocating in a loop as this test
241 // does.
242 //
243 // Because there are two concurrent threads, there's at least the guarantee
244 // of having two unique thread IDs in the set. But after those two threads are
245 // joined, the next-created thread can get a re-used ID if the allocation of
246 // the pthread_t structure is taken from the free list. Therefore, there can
247 // be either 2 or 3 unique thread IDs in the set at this stage in the test.
248 EXPECT_TRUE(unique_threads_.size() >= 2 && unique_threads_.size() <= 3)
249 << "unique_threads_.size() = " << unique_threads_.size();
235 EXPECT_EQ(1, peer_.num_idle_threads()); 250 EXPECT_EQ(1, peer_.num_idle_threads());
236 EXPECT_EQ(4, counter_); 251 EXPECT_EQ(4, counter_);
237 } 252 }
238 253
239 } // namespace base 254 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698