0
톰이 c11 (gcc6)의 threadsafe에서 연결된 목록 구현을 시도하고 있습니다. 내가 얼마나 많은 뮤텍스 잠금을 얻지 못하고 잠금을 해제해야합니까? mutex가있는 threadsafe 코드
/**
* adds a new node to head of the list, alocation of node is done dynamically
* @param list address of list
* @param data pointer to data
*/
void add_head(Linked_list* list, void* data)
{
Node *node = (Node*) malloc(sizeof(Node));
//lock
node->data = data;
if (list->head == NULL) {
list->tail = node;
node->next = NULL;
} else {
node->next = list->head;
}
//unlock
//lock
list->head = node;
list->current = node;
list_size ++;
//unlock
}
또는
/**
* adds a new node to head of the list, alocation of node is done dynamically
* @param list address of list
* @param data pointer to data
*/
void add_head (Linked_list* list, void* data)
{
Node *node = (Node*) malloc(sizeof(Node));
//lock
node->data = data;
if (list->head == NULL) {
list->tail = node;
node->next = NULL;
} else {
node->next = list->head;
}
//unlock
//lock
list->head = node;
//unlock
//lock
list->current = node;
//unlock
//lock
list_size ++;
//unlock
}
는 방법을 찾고
/**
* adds a new node to head of the list, alocation of node is done dynamically
* @param list address of list
* @param data pointer to data
*/
void add_head(Linked_list* list, void* data)
{
Node *node = (Node*) malloc(sizeof(Node));
//lock
node->data = data;
if (list->head == NULL) {
list->tail = node;
node->next = NULL;
} else {
node->next = list->head;
}
list->head = node;
list->current = node;
list_size ++;
//unlock
}
또는
내가 10에 작은 지속 시간의 많은 작업 읽기를해야하기 때문에 다른 스레드가 너무 많이 기다리게하지 않으려면 파일에서 바이트, 메모리에서 10 바이트 변경, 10 바이트 파일을 작성하십시오. 이 기능add_head()
의 구현을 위해
threadsafe
을 지원하려는 때문에