...
| Code Block | ||||
|---|---|---|---|---|
| ||||
void thread_foo(void *ptr) {
uint32_t num;
int result;
/* sock is a connected TCP socket */
if ((result = recv(sock, (void *)&num, sizeof(uint32_t), O_NONBLOCK)) < 0) {
/* Handle Error */
}
if ((result = mtx_lock(&mutex)) != thrd_success) {
/* Handle Error */
}
/* ... */
if ((result = mtx_unlock(&mutex)) != thrd_success) {
/* Handle Error */
}
}
|
Exceptions
CON36-EX1: A thread may block while holding one or more locks and waiting to acquire another lock. When acquiring multiple locks, the order of locking must avoid deadlock, as specified in CON35-C. Avoid deadlock by locking in predefined order.
...
[Barney 2010] POSIX Threads Programming
[Open Group] pthread_cancel(), recv()
...