[완료] 쓰레드 생성이 안되는 이유가 뭐죠?
글쓴이: kkume / 작성시간: 화, 2009/02/10 - 10:09오전
while (1) {
clnt_addr_size = sizeof(clnt_addr);
rcv_len = recvfrom(serv_sock, rbuf, BUF_SZ, 0,
(struct sockaddr *)&clnt_addr, (socklen_t *)&clnt_addr_size);
printf("%s:%d: UDP Connected with %s:%d\n", __FILE__, __LINE__,
inet_ntoa(clnt_addr.sin_addr), ntohs(clnt_addr.sin_port));
/* UDP Thread NOT Created. why?? */
/* Create Thread for new connection */
pthread_create(&thread, NULL, udpRecvThread, &serv_sock);
pthread_join(serv_sock, &retval);
}
void *udpRecvThread(void *arg)
{
int sock = *((int *)arg);
int i, rcv_len = 0;
char rbuf[BUF_SZ] = {0};
printf("UDP receive thread created.\n");
rcv_len = read(sock, rbuf, sizeof(rbuf));
printf("rcv_len=%d, rbuf=[", rcv_len);
for (i = 0; i < rcv_len; i++) {
printf("%02X ", (unsigned char)rbuf[i]);
}
printf("\n\n");
close(sock);
}UDP 수신 부를 쓰레드로 따로 분리하여 처리 하려고 하는데, 쓰레드 함수로 넘어 가질 않네요..
뭐가 잘못 된 거죠?
UDP 수신부를 쓰레드로 따로 처리를 할려면 어떻게 해야 하는지요?
Forums:


man
man pthread_create
PTHREAD_CREATE(3P) POSIX Programmer’s Manual PTHREAD_CREATE(3P) PROLOG This manual page is part of the POSIX Programmer’s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME pthread_create - thread creation ... RETURN VALUE If successful, the pthread_create() function shall return zero; other- wise, an error number shall be returned to indicate the error. ERRORS The pthread_create() function shall fail if: EAGAIN The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process {PTHREAD_THREADS_MAX} would be exceeded. EINVAL The value specified by attr is invalid. EPERM The caller does not have appropriate permission to set the required scheduling parameters or scheduling policy. The pthread_create() function shall not return an error code of [EINTR]. The following sections are informative. ... COPYRIGHT Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at <a href="http://www.opengroup.org/unix/online.html" rel="nofollow">http://www.opengroup.org/unix/online.html</a> . IEEE/The Open Group 2003 PTHREAD_CREATE(3P)OTL
댓글달고보니, man
댓글달고보니, man pthread_join 도 옮겼어야했다는 아쉬움이 남는군요.
필히 보시길 바랍니다.
OTL
댓글 달기