Linux???????????????mutex??
???????????? ???????[ 2013/7/2 10:45:29 ] ????????
????????????????????????????POSIX?????????????????????????е???????????????????????????????????????????????У????????????????????????н??????????
????????????????????????????????????????????????????????????????????????????????????????κ?????????????????????????????
???????????????????pthread_mutex_t???????????<bits/pthreadtypes.h>???о??????塣
????1???????????????????
/* Initialize a mutex. */
int pthread_mutex_init (pthread_mutex_t *__mutex?? __const pthread_mutexattr_t *__mutexattr);
/* Destroy a mutex. */
int pthread_mutex_destroy (pthread_mutex_t *__mutex);
?????????????????????????????????????????
?????????????????????????????????????г?????????£?
pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER;
???????????????pthread_mutex_init()???г?????????????????????????????????????г???????????????????г??????pthread_mutex_init()???????????????????????????????????????????????????NULL??
???????????????????????????????pthread_mutex_destroy()????????????????????
????2??????????????????
/* ?????????????????? */
int pthread_mutexattr_init (pthread_mutexattr_t *__attr);
/* ???????????????? */
int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr);
/* ?????????????????????乲???????? */
int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *__restrict __attr?? int *__restrict __pshared);
/* ????????????????????????乲????? */
int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr?? int __pshared);
?????????????????????pthread_mutex_init????????????????????????????NULL???????????????????
????????????????????????pthread_mutexattr_t????????????????????????????????????????????????????????????ò?????????????????????????????г???????????????????????pthread_mutexattr_setpshared???????????????????????????乲????????????????????????????????????????????????λ?????????????????
????pthread_mutexattr_setpshared()??????????????__pshared?????趨??????乲????????????PTHREAD_PROCESS_PRIVATE??PTHREAD_PROCESS_SHARED???????????y???乲???
??????????????????????????乲?????1????
pthread_mutex_t *pSharedMutex; //?????????????????
pthread_mutexattr_t mutexAttr; //??????????
pSharedMutex = /*??????????????????*/;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_setpshared(&mutexAttr?? PTHREAD_PROCESS_SHARED);
pthread_mutex_init(pSharedMutex?? &mutexAttr);
????3?????????????
/* Try locking a mutex. */
int pthread_mutex_trylock (pthread_mutex_t *__mutex);
/* Lock a mutex. */
int pthread_mutex_lock (pthread_mutex_t *__mutex);
/* Unlock a mutex. */
int pthread_mutex_unlock (pthread_mutex_t *__mutex);
??????????????????????pthread_mutex_lock()??????÷?????????????????????????????????????????????ú???????????????????????????????? pthread_mutex_trylock()??????????????????????????????????????????EBUSY????????????????????????pthread_mutex_unlock() ????????????????????????????????????????
????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????ж??????????????????????????????????????????????????????????????????????????CPU?????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11