469,903 Members | 2,067 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Thread Safe bug-hunt...

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

May 19 '06 #1
1 1742
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
May 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by nicolas_riesch | last post: by
22 posts views Thread by Morpheus | last post: by
13 posts views Thread by arun.darra | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.