The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]




Версия для распечатки Пред. тема | След. тема
Новые ответы [ Отслеживать ]
Проблема с pthread_create в FreeBSD-2.2.8, !*! Eleton Dessu, 03-Окт-01, 02:02  [смотреть все]
Строка pthread_create() вызывает SIGSEGV
и примерчик падает в кору.
Кто-нибудь в курсе данной проблемы, что может быть не учтено?

Образец кода ниже
----
#include <errno.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>

#define socklen_t       unsigned int

static void *coms(void *arg)                                                  
{                                                                              
  pthread_detach(pthread_self());                                              
  printf("Accept TEST\n");                                                    
  write((int)arg, "Test", sizeof("test"));                                    
  printf("Wrote TEST\n");                                                      
  close((int)arg);                                                            
  return(NULL);                                                                
}                                                                              
                                                                              
int main(int argc, char **argv)                                                
{                                                                              
  int *confd, len, lisfd;                                                      
  struct sockaddr_un *client, saun;                                            
                                                                              
  lisfd = socket(AF_UNIX, SOCK_STREAM, 0); unlink("/tmp/TS");                  
  saun.sun_family = AF_UNIX; strcpy(saun.sun_path, "/tmp/TS");                
  bind(lisfd, (struct sockaddr *) &saun, sizeof(struct sockaddr_un));          
  listen(lisfd, 2); printf("Listening\n");                                    
                                                                              
  client = (struct sockaddr_un *)malloc(sizeof(saun));                        
  confd = (int *)malloc(sizeof(int));                                          
  for ( ; ; ) {                                                                
    len = sizeof(saun);
    *confd = accept(lisfd, (struct sockaddr *) client, &len);
    pthread_create(NULL, NULL, &coms, confd);
    printf("PThread created\n");
  }
  return(0);
}




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру