[英]error return code from pthread_create is 35 error due to many processes,I have used pthread_exit which should kill the thread isn't it?
I have create a pthread_create inside a pthread_create, I have used socket programming, where I receive a packet and then create a thread which does the writing to the file. 我在pthread_create内创建了一个pthread_create,使用了套接字编程,在这里我收到一个数据包,然后创建一个线程来写文件。 When I send a very large file, i get this error...??
当我发送一个很大的文件时,出现此错误...?
The code is as follows... 代码如下...
void *writePack(void *sock)
{
size_t nbyte;
ssize_t writeSize;
nbyte = 1466;
off_t offset;
offset = (((struct writePacket *)sock)->seq * 1466);
char* buffer = new char();
buffer = ((struct writePacket *)sock)->datamsg;
writeSize = pwrite(((struct writePacket *)sock)->pp,(const void *)buffer, nbyte, offset );
free(buffer);
pthread_exit(NULL);
}
this is the code of the parent receive code... 这是父母的代码接收代码...
recvfrom(sockA->sockid, (void *)&recvdata, sizeof(struct data), 0, (struct sockaddr *) &cli_addr, &clilen);
if (n<0)
error("Error on reading");
pthread_mutex_lock(&qlock);
struct writePacket* a;
a=new writePacket;
a->sockID = sockA->sockid;
a->pp = sockA->pp;
a->seq = recvdata.seq;
memcpy(a->datamsg,recvdata.datamsg,1466);
pc = pthread_create(&write[counter], NULL, writePack,(void *) a);
if (pc)
{
printf("ERROR; return code from pthread_create() is %d\n", pc);
exit(-1);
}
It could be that the threads you create didn't get a chance to execute, while you've been creating more and more threads reading from the socket. 当您创建越来越多的从套接字读取的线程时,创建的线程可能没有执行的机会。
Instead, create a thread that would do the reading from the socket, another thread that would do the writing, and pass the data in messages between the two threads. 相反,创建一个将执行从套接字读取操作的线程,另一个将执行写入操作的线程,然后在两个线程之间的消息中传递数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.