3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 /* Test of gpr thread local storage support. */
21 #include "src/core/lib/gpr/tls.h"
26 #include <grpc/support/log.h>
27 #include <grpc/support/sync.h>
29 #include "src/core/lib/gprpp/thd.h"
30 #include "test/core/util/test_config.h"
32 #define NUM_THREADS 100
34 GPR_TLS_DECL(test_var);
36 static void thd_body(void* arg) {
39 GPR_ASSERT(gpr_tls_get(&test_var) == 0);
41 for (i = 0; i < 100000; i++) {
42 gpr_tls_set(&test_var, i);
43 GPR_ASSERT(gpr_tls_get(&test_var) == i);
45 gpr_tls_set(&test_var, 0);
48 /* ------------------------------------------------- */
50 int main(int argc, char* argv[]) {
51 grpc_core::Thread threads[NUM_THREADS];
53 grpc::testing::TestEnvironment env(argc, argv);
55 gpr_tls_init(&test_var);
57 for (auto& th : threads) {
58 th = grpc_core::Thread("grpc_tls_test", thd_body, nullptr);
61 for (auto& th : threads) {
65 gpr_tls_destroy(&test_var);