orange-guo commented on code in PR #614: URL: https://github.com/apache/guacamole-server/pull/614#discussion_r2384989493
########## src/libguac/tests/thread-local/thread_local_storage_multithreaded.c: ########## @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <CUnit/CUnit.h> +#include <guacamole/thread-local.h> + +#include <stdlib.h> +#include <pthread.h> +#include <unistd.h> + +static guac_thread_local_key_t test_key; +static int destructor_call_count = 0; +static pthread_mutex_t destructor_mutex = PTHREAD_MUTEX_INITIALIZER; + +/** + * Destructor function for testing cleanup. + */ +static void test_destructor(void* value) { + pthread_mutex_lock(&destructor_mutex); + destructor_call_count++; + pthread_mutex_unlock(&destructor_mutex); + free(value); +} + +/** + * Thread worker function for multithreaded tests. + */ +static void* thread_worker(void* arg) { + int thread_id = *(int*)arg; + + /* Each thread sets its own value */ + int* test_value = malloc(sizeof(int)); + *test_value = thread_id * 100; + + CU_ASSERT_EQUAL(guac_thread_local_setspecific(test_key, test_value), 0); + + /* Small delay to increase chance of race conditions */ + usleep(1000); Review Comment: Removed the artificial usleep(1000) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
