Unix Programming - issues with threaded program

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2004 > issues with threaded program





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author issues with threaded program
El Durango

2004-03-21, 5:34 am

Hi I am working on a client-server program in which the server creates a
thread each time a client successfully connects. However it seems that the
function that the pthread_create calls does not seem to run?
Basically the function will itself act as a polling mechanism on the server
end where it will await client instructions here are the main snippets of
code that I am talking about :

/* create threads for every client after successfully addressing the client
*/
if(msgsnd(imsqid, &initmsg, sizeof(initmsg), 0) == 0){
printf("Message sent to client %d\n", clicount);
nmsqid = msgget(newkey, IPC_CREAT|PERM);
pthread_create(&thread_tbl[threadcount], NULL, &acceptCli,
(void*)nmsqid);
threadcount++;
}

/* the function called by pthread_create */
void *acceptCli(void *msqid){
int connected = TRUE;
int retval = -1;
cmdmesg cmdmsg;
memset(&cmdmsg, 0, sizeof(cmdmsg));
while(connected){
do{
/* receive the first message on the queue */
retval = msgrcv((int)msqid, &cmdmsg, sizeof(cmdmsg), 1, 0);
}while(retval < 0);
switch(cmdmsg.cmd)
{
case 0:
printf("unknown command sent\n");
break;
case 1:
printf("read command sent\n");
break;
case 2:
printf("get command sent\n");
break;
case 3:
printf("put command sent\n");
break;
case 4:
printf("help command sent\n");
break;
case 5:
printf("quit command sent\n");
connected = FALSE;
break;
}
}
pthread_exit(NULL);
}

I also have to mention that the only way that thread should end is if a
"quit" command was sent or the server terminates, which it should'nt since
it is in a continous loop.

If anyone can clear this up for me I would appreciate it!
thanks!


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com