try tom сделать мой связанный список в c11 (gcc6), потокобезопасным. только я не получаю, сколько замков и разблокировок мьютексов я должен идти?threadafe code with mutex
/**
* 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
}
или
/**
* 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
}
ищет способ, чтобы не сделать другой поток ждать слишком много, так как у меня будет много задачи крошечной продолжительности времени чтения до 10 байт из файла, изменить 10 байт в памяти, записать 10 байтов.