int f(int);
argument * argument_used_in_first_call_to_function
我编码如下.即使它是线程安全的,它不快,因为它使用互斥锁定/解锁.在线程安全的同时还有更快的解决方案吗?
mutex mut1; int f(int x) { pthread_mutex_lock(mut1); static bool first_init = true; static int first_arg = 0; if (first_init) { first_arg = x; first_init = false; } pthread_mutex_unlock(mut1); return x * first_arg; }