LINUX.ORG.RU

Закрытие мьютекса перед удалением структуры


0

1

Не знаю. Cтоит ли ожидать «подводных камней» в данном случае. Не останется ли какой мусор который обычно удаляется нормально через pthread_mutex_destroy?

Условный пример:

typedef struct foo {
 pthread_mutex_t lock;
 ...
} foo_t;

foo_t *
foo_new ()
{
  ... allocate memory
  pthread_mutex_init (&foo->lock);
  return (foo);
}

void
foo_free (foo_t *foo)
{
 ... something check
 pthread_mutex_lock (&foo->lock);
 free (foo);
}

Спасибо!



Последнее исправление: friniz (всего исправлений: 1)

man pthread_mutex_destroy

pthread_mutex_destroy destroys a mutex object, freeing the resources it might hold. The mutex must be unlocked on entrance. In the LinuxThreads implementation, no resources are associated with mutex objects, thus pthread_mutex_destroy actually does nothing except checking that the mutex is unlocked.

i-rinat ★★★★★
()

Делай мьютексу дестрой. При этом мьютекс не должен быть залочен.

yoghurt ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.