Hi,
[Sorry for comp.lang.c some folks may find it OT]
In Mulithreaded program, using Posix api, we do
pthread_mutex_l ock(&Lock)
do some ops
if/else/if/else...complex stuff
pthread_mutex_u nlock.
now assume because of complex if/else/if/else, thread got exited
without unlocking the mutex. :)
now the funny part is, other thread trying to acquire lock will
block. How to detect which thread [may be exited thread !!!!] has done
some wrong stuff. But how to track them?
Before few days i posted, why not to unlock all mutex acquired by
thread "A" when thread "A" is exiting/finishing/cancelled/thrown outof
system. !
Please note: from my code i can do manually logs and debug message
monitoring and can findout. What i am more interested in is, "How to
Autodetect and how to avoid, even code is done by ***Lazy***
programmer."
Any thought ?
Cheers,
Raxit 8 2198
On May 21, 4:11 pm, "Ra...@MyKavita .com" <raxitsheth2... @gmail.com>
wrote:
Hi,
[Sorry for comp.lang.c some folks may find it OT]
Then why did you post it to comp.lang.c? It doesn't matter who will
find it OT or not, what matters is that your question is not topical
for comp.lang.c. Use common sense.
Hi! Ra***@MyKavita. com schrieb:
now assume because of complex if/else/if/else, thread got exited
without unlocking the mutex. :)
now the funny part is, other thread trying to acquire lock will
block. How to detect which thread [may be exited thread !!!!] has done
some wrong stuff. But how to track them?
Encapsulate the lock and unlock calls in debug builds by a funtion that
does some logging to a file. Always log a timestamp, the called function
(lock/unlock), the address of the Lock and the thread ID. Once you have
a deadlock simply analyze the log and search for the last occourencies
of the handle address of the last call to lock that never returned. You
will find the thread ID of the thread that never unlocked the mutex this
way.
If you frequently start threads, you should also track the thread starts
with some meaningful text to associate a meaningful context with the
thread ID.
Most Unix kernels provide atomic append functions for small amount of
output. So you do not need another mutex to serialize the output.
Before few days i posted, why not to unlock all mutex acquired by
thread "A" when thread "A" is exiting/finishing/cancelled/thrown outof
system. !
You should not compensate for program bugs this way. It is not that
unlikely that other cleanup is also wrong in this case.
Please note: from my code i can do manually logs and debug message
monitoring and can findout. What i am more interested in is, "How to
Autodetect and how to avoid, even code is done by ***Lazy***
programmer."
There is no general way to autodetect deadlocks or unpaired mutex calls.
Only in some rare cases you may catch them safely.
But if C++ is a choice you may use a helper class whose constructor
aquires the lock and whose destructor releases the lock. This is solid
as rock! It is nearly impossible to prevent the destructor call even in
case of exceptions.
Marcel
On May 21, 6:11 am, "Ra...@MyKavita .com" <raxitsheth2... @gmail.com>
wrote:
[Sorry for comp.lang.c some folks may find it OT]
Apparently everything related to C is off topic in this newsgroup.
Only the very act of being nit-picky about the current ISO standard is
sanctioned here.
In Mulithreaded program, using Posix api, we do
pthread_mutex_l ock(&Lock)
do some ops
if/else/if/else...complex stuff
pthread_mutex_u nlock.
now assume because of complex if/else/if/else, thread got exited
without unlocking the mutex. :)
now the funny part is, other thread trying to acquire lock will
block. How to detect which thread [may be exited thread !!!!] has done
some wrong stuff. But how to track them?
This is a debugging problem. A Mutex is a lock that is assigned to a
particular thread. A good multi-threaded system should have a way, in
your debugger to know who owns the lock; in fact you might be able to
inspect that from your API (by having a time-out on your MUTEX) and
throw it into some log file somewhere -- i.e., directly instrument
your code to do this sort of analysis. Whenever I have implemented my
own Mutexes from scratch, what I did was I would shove the __FILE__,
__LINE__ macros into the mutex structure to identify the owner because
the point in the code where the Mutex got owned without cleared was
usually more relevant than the thread ID.
Before few days i posted, why not to unlock all mutex acquired by
thread "A" when thread "A" is exiting/finishing/cancelled/thrown outof
system. !
As I said -- this is a debugging problem. You have an error in your
code. You need to isolate the error, not try to vacate the problem
with some trick.
Please note: from my code i can do manually logs and debug message
monitoring and can findout. What i am more interested in is, "How to
Autodetect and how to avoid, even code is done by ***Lazy***
programmer."
This is like the halting problem -- there isn't really a full-proof
way. You can, of course, make a macro with both acquires the lock and
releases it:
#define WITH_MUTEX(mute x,code) { \
int h = mutexAcquire (mutex); \
if (SUCCESS == h) { \
do { code } while (0); \
mutexRelease (mutex); \
} \
}
And in fact you could put in a try+catch thing for C++ to make sure
that you don't escape that way. So you can then set a coding
standard, and in fact have some tool grep through the code and
complain about bare calls to the mutex primitives instead of using the
macro above. But of course, you cannot avoid longjmp() or coroutine
yields anyways, so even with this limited usage there are no
guarantees.
--
Paul Hsieh http://www.pobox.com/~qed/ http://bstring.sf.net/
In article <d5************ *************** *******@h1g2000 prh.googlegroup s.com>,
Paul Hsieh <we******@gmail .comwrote:
>On May 21, 6:11 am, "Ra...@MyKavita .com" <raxitsheth2... @gmail.com> wrote:
>[Sorry for comp.lang.c some folks may find it OT]
>Apparently everything related to C is off topic in this newsgroup. Only the very act of being nit-picky about the current ISO standard is sanctioned here.
So, Paul, what do you think about the tradeoffs of using 10W20
as compared to 10W30? And does it make a difference whether it is
synthetic or natural? My wife has cut down on her car use, but
it isn't uncommon for her to pick me up in her 95 Accord after work,
especially if we have to go grocery shopping. The temperature range
here is from about -45C to +35C, with -15C or so being pretty common
in winter outside of the cold snaps; the summer tends to about +25C.
This is, of course, a real-world C situation (since I am a C
programmer), so I figure comp.lang.c oughta be cool with it.
--
"And that's the way it is." -- Walter Cronkite
Paul Hsieh wrote:
On May 21, 6:11 am, "Ra...@MyKavita .com" <raxitsheth2... @gmail.com>
wrote:
>[Sorry for comp.lang.c some folks may find it OT]
Apparently everything related to C is off topic in this newsgroup.
Only the very act of being nit-picky about the current ISO standard is
sanctioned here.
Some people think that posting bullshit claiming that
things-related-to-C are unwelcome in the newsgroup [apparently
comp.lang.c, only one of the three Paul Hsieh crossposted to] is just
what the doctor ordered. It's certainly a lie about comp.lang.c, and
has zero relevance to comp.unix.progr ammer or comp.programmin g.threads.
It is worth noting, that almost nothing can possibly be topical in all
three of the newsgroups to which this thread is crossposted.
I seem to have removed my anti-gmail filter to soon. I'll just
reintroduce one for Paul "Nitwit" Hsieh.
Martin Ambuhl wrote:
Paul Hsieh wrote:
.... snip ...
>
>Apparently everything related to C is off topic in this newsgroup. Only the very act of being nit-picky about the current ISO standard is sanctioned here.
Some people think that posting bullshit claiming that
things-related-to-C are unwelcome in the newsgroup [apparently
comp.lang.c, only one of the three Paul Hsieh crossposted to] is
just what the doctor ordered. It's certainly a lie about
comp.lang.c, and has zero relevance to comp.unix.progr ammer or
comp.programmin g.threads.
It is worth noting, that almost nothing can possibly be topical in
all three of the newsgroups to which this thread is crossposted.
I seem to have removed my anti-gmail filter to soon. I'll just
reintroduce one for Paul "Nitwit" Hsieh.
The problem with Hsieh is that he is often violently off-topic here
(in c.l.c), but occasionally makes useful and interesting topical
quotes.
I have set follow-ups to c.l.c, where this is entirely off-topic.
The other groups may well be topical.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
CBFalconer <cb********@yah oo.comwrites:
[...]
I have set follow-ups to c.l.c, where this is entirely off-topic.
The other groups may well be topical.
Are you sure that's what you meant to do, or did you want to redirect
followups to the *other* groups? (This is cross-posted to all three
groups; please limit followups as appropriate.)
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Keith Thompson wrote:
CBFalconer <cb********@yah oo.comwrites:
[...]
>I have set follow-ups to c.l.c, where this is entirely off-topic. The other groups may well be topical.
Are you sure that's what you meant to do, or did you want to
redirect followups to the *other* groups? (This is cross-posted
to all three groups; please limit followups as appropriate.)
Yup. Because, having snipped it, it only deals with topicality on
c.l.c. Confusing, isn't it? I think this is the right thing to
do.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com ** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John P. Speno |
last post by:
So you have this problem, and you decide to use threads to solve it...
System is Python 2.3.3 on Solaris 9.
I'm using the classic Python thread model. Main thread puts stuff into
a Queue.Queue() and worker threads get stuff out of it and do their thing.
On occaision, I get an exception in the main thread when it tries to
put something into the Queue.
|
by: Dan Jones |
last post by:
I'm writing a script to process a directory tree of images.  In each
directory, I need to process each image and generate an HTML file listing
all of the images and links to the subdirectories.
Just about every source I can find on the 'net for processing subdirectories
points you at Find::Find.  However, I'm trying to do something like this:
enter directory
open INDEX, ".\index.html"
print INDEX HTMLheader
|
by: monomaniac21 |
last post by:
Hi everyone
i'm trying to setup my website to create new webpages dynamically using
php but I am have a major problem in that whenever i create a file it
is always created locked so that it can only be read even when i
specify read and write access.
Here is a basic example of the code I am using (I am using a Mac OSX
10.3.9):
|
by: DD |
last post by:
I'm not sure that this msg made it out, the first time I sent it, so I
am trying again. --
Win XP Home Edition
I use System.Diagnostics.Process.GetProcesses()) to get info about the
processes running.
I don't see any members of class' Process' which allows me to get the
name of the owner of the process.
|
by: NewToCPP |
last post by:
There are several occations where we write onto someone else' memory
region. Is there any debugging mechanism to find out which part of the
code is causing this problem?
| |
by: UJ |
last post by:
Is there a way to get a list of all the mutexes that have already been
defined?
TIA - Jeff.
|
by: drawoh |
last post by:
Hi All,
I have a class that creates a thread, a mutex and a condition variable
in its constructor. I am writing a copy constructor for this class in
C++. I am doing a simple copy using the member initialization list.
First of all, does anyone have any opinion about whether this will work
fine. I think it will. I believe a copy constructor, when using a
member initialization list, does a memory copy of the object's members
to be copied....
|
by: Dave |
last post by:
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried looking at
ProcessStartInfo.UserName but that was empty - I presume that's more for new
starting processes than examining the current one.
--
Dave
|
by: pbd22 |
last post by:
Hi.
I have a C# program that fires an external VB6 program which writes to
a file and terminates.
It is ugly, but this is how I have to do it. I cannot change this part
of the program.
The problem I am encountering is that the former process created by
this EXE is not complete
(it runs for a few seconds) when the next one wants to start. A
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |