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. 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.
精彩评论