Thread Safe bug-hunt...

Discussion in 'C Programming' started by Bill, May 19, 2006.

  1. Bill

    Bill Guest

    Hi all,
    I've got my self a bug that I am out of ideas on how to fix...
    A section of my program launches a thread to handle a FIFO work buffer,

    I make the fifo as a single link list, the head node is set to NULL
    when the buffer is empty by the handler thread.

    One or more ( typicaly 3 or 4 ) request threads are used to place
    objects on to the work que.

    Both the request and handler threads wait to establish ownership of a
    mutex lock before adding to or freeing from the que.

    The bug shows up when one of the request threads finds the work que
    empty and adds it request. occasionaly the request gets clobbered by
    one of the other threads.

    I suspect the mutex lock is not working correctaly, but I have tested
    it and can see threads having to wait for the lock ( both using gdb and
    simple prints ), so I am at a loss of how a request could be getting
    clobberd.

    The suspect code from the handeler is:

    while( epicsMutexLockOK != epicsMutexLock(*lock) ){
    epicsThreadSleep(0);
    printf("waiting to free\n");
    }
    callbackRequest(pdpvt->call);
    /* Advance the que */
    pport->que = que->next;
    /* free the one we just finished */
    fprintf(stderr,"Freeing %s\n",prec->name);
    free(que->send);
    free(que);
    epicsMutexUnlock(*lock);

    And from the requesting threads:
    while( epicsMutexLockOK != epicsMutexLock(*lock)){
    printf("wiat for lock:ai\n");
    epicsThreadSleep(0);
    }
    if(pport->que){
    que = pport->que;
    while(que->next){
    que = que->next;
    }
    que->next = request;
    DEBUG(6,("Adding to NON empty Que\n"));
    }
    else{
    DEBUG(6,("Adding to empty Que\n"));
    pport->que = request;
    if(pport->que != request){
    fprintf(stderr,"Did not add to Que!!");
    }
    }
    epicsMutexUnlock(*lock);


    Any help, pointers, or pointing out of stupid mistakes ( other than my
    lousy spelling ) Would be very much welcome.

    --Bill
    Bill, May 19, 2006
    #1
    1. Advertising

  2. Bill

    CBFalconer Guest

    Bill wrote:
    >
    > I've got my self a bug that I am out of ideas on how to fix...
    > A section of my program launches a thread to handle a FIFO work
    > buffer,


    C has no provision for threads. This is system specific, and thus
    OT on c.l.c. Try a newsgroup with 'thread' in its name, or a group
    specific to your system.

    --
    "The most amazing achievement of the computer software industry
    is its continuing cancellation of the steady and staggering
    gains made by the computer hardware industry..." - Petroski
    CBFalconer, May 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mark | r

    bug hunt

    mark | r, May 26, 2004, in forum: HTML
    Replies:
    11
    Views:
    924
    Sid Ismail
    May 27, 2004
  2. jimspace

    Subtle Bugs in c++ hunt

    jimspace, May 4, 2005, in forum: C++
    Replies:
    7
    Views:
    427
    John Carson
    May 5, 2005
  3. Replies:
    11
    Views:
    526
    Chris Hills
    Jan 5, 2008
  4. Gabriel Rossetti
    Replies:
    0
    Views:
    1,293
    Gabriel Rossetti
    Aug 29, 2008
  5. John Nagle
    Replies:
    5
    Views:
    448
    John Nagle
    Mar 12, 2012
Loading...

Share This Page