Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个定义信号量的静态库。信号量需要在对库的任何调用之前初始化(因为它可以被来自同一进程的多个线程安全地使用)。
因此,我想在进程启动期间初始化(例如通过运行 sem_init)库的信号量。我怎样才能做到这一点?
// This seems to solve the problem. Init(void) will run before main() void Init(void) __attribute__((constructor)); void Init(void) // This will always run before main() { printf("HSA LIB Init\n"); sem_init (&HSA_lib.semaphore, 0, 1); }