线程安全的pthread互斥锁包装(Thread safe pthread mutex lock wrappers)
我正在编写一个操作系统抽象库,为此我想在Linux上为pthread互斥体编写包装器。
这段代码应该被多个线程调用。
代码如下所示:
int my_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } 函数my_lock是否也是线程安全的? 如果没有,如何使它线程安全?I am writing a OS abstraction library for which i want to write wrappers for pthread mutex over Linux.
This code shall be called by multiple threads.
The code goes something like this:
int my_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } Will the function my_lock also will be thread-safe? If not, How to make it thread-safe?最满意答案
这是你发布的功能:
int my_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); }为什么你甚至需要这里的功能?
该代码是线程安全的,因为您已经提供了它。
This is what you posted as your function:
int my_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); }Why do you even need the function here?
The code is thread-safe as you have presented it.
更多推荐
发布评论