issues with threaded program
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > issues with threaded program




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    issues with threaded program  
El Durango


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-21-04 10: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!







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:04 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register