1 /*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <dlfcn.h>
16 #include <pthread.h>
17
18 #include "test.h"
19
20 const char* g_libPath = "libdl_multithread_test_dso.so";
21 static bool stop = false;
22
dl_testnull23 static void* dl_test()
24 {
25 while (!stop) {
26 void* handle = dlopen(g_libPath, RTLD_GLOBAL);
27 if (!handle) {
28 t_error("dlopen(name=%s, mode=%d) failed: %s\n", g_libPath, RTLD_GLOBAL, dlerror());
29 }
30 dlclose(handle);
31 }
32 return 0;
33 }
34
mainnull35 int main()
36 {
37 pthread_t thd1;
38 pthread_t thd2;
39 pthread_t thd3;
40 pthread_t thd4;
41 pthread_t thd5;
42 void *res;
43 pthread_create(&thd1, NULL, dl_test, NULL);
44 pthread_create(&thd2, NULL, dl_test, NULL);
45 pthread_create(&thd3, NULL, dl_test, NULL);
46 pthread_create(&thd4, NULL, dl_test, NULL);
47 pthread_create(&thd5, NULL, dl_test, NULL);
48 sleep(3);
49 stop = true;
50 pthread_join(thd1, &res);
51 pthread_join(thd2, &res);
52 pthread_join(thd3, &res);
53 pthread_join(thd4, &res);
54 pthread_join(thd5, &res);
55 }
56