| 469 | } |
| 470 | |
| 471 | static void launch_many_bthreads() { |
| 472 | g_stop = false; |
| 473 | bthread_t tid; |
| 474 | BthreadCond c; |
| 475 | c.Init(); |
| 476 | butil::Timer tm; |
| 477 | bthread_start_urgent(&tid, &BTHREAD_ATTR_PTHREAD, wait_cond_thread, &c); |
| 478 | std::vector<bthread_t> tids; |
| 479 | tids.reserve(32768); |
| 480 | tm.start(); |
| 481 | for (size_t i = 0; i < 32768; ++i) { |
| 482 | bthread_t t0; |
| 483 | ASSERT_EQ(0, bthread_start_background(&t0, NULL, usleep_thread, NULL)); |
| 484 | tids.push_back(t0); |
| 485 | } |
| 486 | tm.stop(); |
| 487 | LOG(INFO) << "Creating bthreads took " << tm.u_elapsed() << " us"; |
| 488 | usleep(3 * 1000 * 1000L); |
| 489 | c.Signal(); |
| 490 | g_stop = true; |
| 491 | bthread_join(tid, NULL); |
| 492 | for (size_t i = 0; i < tids.size(); ++i) { |
| 493 | LOG_EVERY_SECOND(INFO) << "Joined " << i << " threads"; |
| 494 | bthread_join(tids[i], NULL); |
| 495 | } |
| 496 | LOG_EVERY_SECOND(INFO) << "Joined " << tids.size() << " threads"; |
| 497 | } |
| 498 | |
| 499 | TEST(CondTest, too_many_bthreads_from_pthread) { |
| 500 | bthread_setconcurrency(16); |
no test coverage detected