c - Producer/Consumer using TCP client/server -


the server intended multithreaded server spawns new threads upon either producer or consumer connection via tcp. problem i'm getting stuck in wait state once producer client fills queue. snippet shows server's handling of producer connection. format of request producer sends put (item)

    reqline[0] = strtok (mesg, " \t\n");    if ( strncmp(reqline[0], "put\0", 4)==0 )            {             item[0]=strtok(null," \t\n");             pthread_create (&pro, null, producer, fifo);             pthread_join (pro, null);               } 

so can see i'm creating new thread handles job of filling queue/detecting when empty. code within producer:

    queue *fifo;     int i=atoi(item[0]);     char*fullmsg="full\n";      fifo = (queue *)q;      pthread_mutex_lock (fifo->mut);           while (fifo->full) { //the problem  block                printf ("producer: queue full.\n");               send(conn_s, fullmsg,strlen(fullmsg),0);               pthread_cond_wait (fifo->notfull, fifo->mut);            }              queueadd (fifo, 0);            pthread_mutex_unlock (fifo->mut);            pthread_cond_signal (fifo->notempty); 

i believe wait condition problem. server waiting condition can never met, considering consumer thread not started eat queue. thinking should change condition wait incoming consumer connection , start consumer thread. seems silly within method. if send consumer request while in state nothing happens.

any suggestions appreciated. i'm not sure if design feasible.

your problem seems you're calling pthread_join() after pthread_create(), means main thread stops here until producer exits - can't ever accept consumer connection, producer can't make progress once queue full.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -