473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1900
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: nicolas_riesch | last post by:
Does someone know if the module pytz (http://sourceforge.net/projects/pytz/) is thread-safe ? I have not seen it explicitely stated, and just wanted to be sure, as I want to use it. That's...
22
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
13
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.