Editing Wrapper library
Appearance
Latest revision | Your text | ||
Line 15: | Line 15: | ||
==== C interface ==== |
==== C interface ==== |
||
< |
<source lang="C"> |
||
int pthread_mutex_init(pthread_mutex_t * mutex , pthread_mutexattr_t * attr); |
int pthread_mutex_init(pthread_mutex_t * mutex , pthread_mutexattr_t * attr); |
||
int pthread_mutex_destroy (pthread_mutex_t * mutex); |
int pthread_mutex_destroy (pthread_mutex_t * mutex); |
||
int pthread_mutex_lock (pthread_mutex_t * mutex ); |
int pthread_mutex_lock (pthread_mutex_t * mutex ); |
||
int pthread_mutex_unlock (pthread_mutex_t * mutex ); |
int pthread_mutex_unlock (pthread_mutex_t * mutex ); |
||
</source> |
|||
</syntaxhighlight> |
|||
==== C++ wrapper ==== |
==== C++ wrapper ==== |
||
< |
<source lang="cpp"> |
||
class Mutex |
class Mutex |
||
{ |
{ |
||
Line 69: | Line 69: | ||
} |
} |
||
}; |
}; |
||
</source> |
|||
</syntaxhighlight> |
|||
The original C interface can be regarded as error prone, particularly in the case where users of the library forget to unlock an already locked mutex. The new interface effectively utilizes [[resource acquisition is initialization]] (RAII) in the new {{mono|Mutex}} and {{mono|Lock}} classes to ensure {{mono|Mutex}}s are eventually unlocked and {{mono|pthread_mutex_t}} objects are automatically released. |
The original C interface can be regarded as error prone, particularly in the case where users of the library forget to unlock an already locked mutex. The new interface effectively utilizes [[resource acquisition is initialization]] (RAII) in the new {{mono|Mutex}} and {{mono|Lock}} classes to ensure {{mono|Mutex}}s are eventually unlocked and {{mono|pthread_mutex_t}} objects are automatically released. |