MCPcopy Create free account
hub / github.com/apache/brpc / launch_many_bthreads

Function launch_many_bthreads

test/bthread_cond_unittest.cpp:471–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471static 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
499TEST(CondTest, too_many_bthreads_from_pthread) {
500 bthread_setconcurrency(16);

Callers 2

TESTFunction · 0.70
run_launch_many_bthreadsFunction · 0.70

Calls 11

bthread_start_urgentFunction · 0.85
bthread_start_backgroundFunction · 0.85
bthread_joinFunction · 0.85
u_elapsedMethod · 0.80
InitMethod · 0.45
reserveMethod · 0.45
startMethod · 0.45
push_backMethod · 0.45
stopMethod · 0.45
SignalMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected