Skip to content
Snippets Groups Projects
Commit d719d6e1 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

Merge pull request #5750 from sreecha/gpr_thd_test

Reduce the number of threads so that this test works on x86 systems
parents 85b460fb f7cea976
No related branches found
No related tags found
No related merge requests found
/* /*
* *
* Copyright 2015, Google Inc. * Copyright 2015-2016, Google Inc.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#define NUM_THREADS 300
struct test { struct test {
gpr_mu mu; gpr_mu mu;
int n; int n;
...@@ -79,15 +81,14 @@ static void test_options(void) { ...@@ -79,15 +81,14 @@ static void test_options(void) {
static void test(void) { static void test(void) {
int i; int i;
gpr_thd_id thd; gpr_thd_id thd;
gpr_thd_id thds[1000]; gpr_thd_id thds[NUM_THREADS];
struct test t; struct test t;
int n = 1000;
gpr_thd_options options = gpr_thd_options_default(); gpr_thd_options options = gpr_thd_options_default();
gpr_mu_init(&t.mu); gpr_mu_init(&t.mu);
gpr_cv_init(&t.done_cv); gpr_cv_init(&t.done_cv);
t.n = n; t.n = NUM_THREADS;
t.is_done = 0; t.is_done = 0;
for (i = 0; i != n; i++) { for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(gpr_thd_new(&thd, &thd_body, &t, NULL)); GPR_ASSERT(gpr_thd_new(&thd, &thd_body, &t, NULL));
} }
gpr_mu_lock(&t.mu); gpr_mu_lock(&t.mu);
...@@ -97,10 +98,10 @@ static void test(void) { ...@@ -97,10 +98,10 @@ static void test(void) {
gpr_mu_unlock(&t.mu); gpr_mu_unlock(&t.mu);
GPR_ASSERT(t.n == 0); GPR_ASSERT(t.n == 0);
gpr_thd_options_set_joinable(&options); gpr_thd_options_set_joinable(&options);
for (i = 0; i < n; i++) { for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(gpr_thd_new(&thds[i], &thd_body_joinable, NULL, &options)); GPR_ASSERT(gpr_thd_new(&thds[i], &thd_body_joinable, NULL, &options));
} }
for (i = 0; i < n; i++) { for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(thds[i]); gpr_thd_join(thds[i]);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment