Код: Выделить всё
void clear_list(void *arg, int kill_threads){
if (!arg)
return;
ClientList *list = (ClientList*)arg;
if (!IS_EMPTY_LIST(list)){
pthread_mutex_lock(&list->lock);
ClientList *elem;
int ret = 0;
//Cleaning all resources used by threads
//FIXME: ??? after processing 1 element, list becomes 0x0
for (elem = list->next; elem != list; elem = elem->next){ //Перебираем все элементы списка, переменная list является головой списка, поэтому ее не трогаем
if (pthread_join(*elem->client->thr, (void**) & ret) != 0) //После вызова переменная list обнуляется
perror("pthread_join");
else {
printf("[0x%x]: Exited with %i code.\n"
, elem->client->thr, (int) (long) ret);
if (kill_threads)
pthread_cancel(*elem->client->thr);
free(elem->client->thr);
if (elem->client->file)
free(elem->client->file);
}
}
..............
}
}Проверил отладчиком, оказалось что переменная list обнуляется после вызова pthread_join().
Вот структуры ClientList и Client:
Код: Выделить всё
struct Client {
int sd;
int connected;
int logged;
char *file;
int fd;
off_t offset;
unsigned int flen;
void *data;
pthread_t *thr;
};
struct ClientList {
pthread_mutex_t lock;
Client *client;
ClientList *next;
ClientList *prev;
};Если в место list использовать ((ClientList*)arg), то все отрабатывает на ура. Не пойму в чем дело...
P.S.
Код: Выделить всё
negativ@negativ-zet:~$ g++ --version
g++ (GCC) 4.4.0
Copyright (C) 2009 Free Software Foundation, Inc.
negativ@negativ-zet:~$ uname -a
Linux negativ-zet 2.6.29.1 #3 SMP Wed Apr 22 03:43:52 MSD 2009 x86_64 GNU/Linux
negativ@negativ-zet:~$ gdb --version
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".