aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/gpr/cpu_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/gpr/cpu_test.cc')
-rw-r--r--test/core/gpr/cpu_test.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc
index 9f2c3f1923..c97facef7d 100644
--- a/test/core/gpr/cpu_test.cc
+++ b/test/core/gpr/cpu_test.cc
@@ -101,7 +101,7 @@ static void cpu_test(void) {
uint32_t i;
int cores_seen = 0;
struct cpu_test ct;
- gpr_thd_id thd;
+ gpr_thd_id* thd;
ct.ncores = gpr_cpu_num_cores();
GPR_ASSERT(ct.ncores > 0);
ct.nthreads = static_cast<int>(ct.ncores) * 3;
@@ -110,15 +110,22 @@ static void cpu_test(void) {
gpr_mu_init(&ct.mu);
gpr_cv_init(&ct.done_cv);
ct.is_done = 0;
- for (i = 0; i < ct.ncores * 3; i++) {
- GPR_ASSERT(
- gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, nullptr));
+
+ uint32_t nthreads = ct.ncores * 3;
+ thd = static_cast<gpr_thd_id*>(gpr_malloc(sizeof(thd[0]) * nthreads));
+
+ for (i = 0; i < nthreads; i++) {
+ GPR_ASSERT(gpr_thd_new(&thd[i], "grpc_cpu_test", &worker_thread, &ct));
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&ct.mu);
+ for (i = 0; i < nthreads; i++) {
+ gpr_thd_join(thd[i]);
+ }
+ gpr_free(thd);
fprintf(stderr, "Saw cores [");
fflush(stderr);
for (i = 0; i < ct.ncores; i++) {