LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-09-2004, 11:38 PM   #1
skdevnath
LQ Newbie
 
Registered: Mar 2004
Location: Fremont, CA
Distribution: red hat
Posts: 3

Rep: Reputation: 0
My thread hangs while writting into a file


Hi guys,

I have a multithreaded program. One of the thread suddenly hangs for for ever. I tried using strace -p to see where exactly it is hanging. Here is the tail of that file

---
write(4, "Mar 9 16:46:51.893 [14318] [EXT"..., 102) = 102
time(NULL) = 1078865211
write(3, "1078865211: 356510: checking hea"..., 34) = 34
time(NULL) = 1078865211
write(3, "1078865211: 356510: *** alloc: a"..., 83) = 83
time(NULL) = 1078865211
write(3, "1078865211: 356511: checking hea"..., 34) = 34
time(NULL) = 1078865211
write(3, "1078865211: 356511: *** alloc: a"..., 103) = 103
time(NULL) = 1078865211
write(3, "1078865211: 356512: checking hea"..., 34) = 34
time(NULL) = 1078865211
write(3, "1078865211: 356512: *** alloc: a"..., 103) = 103
rt_sigprocmask(SIG_SETMASK, NULL, [RTMIN], 8) = 0
rt_sigsuspend([]
---

any idea why this sigsuspend is getting called soon after thread tries to write on fd=3. After this call my thread waits for the signal for for ever. I am not sure, which signal it is.
My process is deamon so stdin/stdout/err is closed.

I have compiled dmalloc library with my program and during this run dmalloc is active by setting DMALLOC_OPTIONS env variable.

Thanks in advance for your response.

Sandip

Last edited by skdevnath; 03-09-2004 at 11:41 PM.
 
Old 03-10-2004, 11:43 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Are you using fork() or pthreads or what? If you're using a wait() or waitpid() function it might do a suspend. Can you paste the code?
 
Old 03-11-2004, 06:13 PM   #3
skdevnath
LQ Newbie
 
Registered: Mar 2004
Location: Fremont, CA
Distribution: red hat
Posts: 3

Original Poster
Rep: Reputation: 0
I was using pthread.

Looks like I found the problem.
The problem what I think is
1). thread1 is about to lock a mutex but at the same time it got schduled out.
2). thread2 frees the c++ object containing the same mutex. The thread's code gets the same mutex lock before deleting the object.
3). Now when thread1 again gets scheduled, it tries to lock the deleted object's mutex and so it waits for ever since the destructor for the object never unlocks the mutex. However it calls pthread_mutex_destroy () on the mutex.
4). Now since that object is deleted for ever and object is unreferenced so thread2 or anybody else never call unlock for same mutex.

Note: My object's destructor calls pthread_mutex_destroy () on same mutes.

So there are little unexplain things are there but I dont like the idea of triying to aquire a lock on deleted object. I solved this problem by puting mutex out of the object at global level. This solution worked for me now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writting to file in php blitzX Programming 2 01-16-2005 03:57 PM
How to Attach a file on my thread? extremebfn LQ Suggestions & Feedback 5 09-05-2004 11:03 PM
Is a file in writting ? stephnane AIX 3 08-03-2004 12:17 AM
Is a file in writting stephnane Linux - General 2 07-30-2004 10:39 PM
??.img file without writting itto CD pudhiyavan Linux - General 4 12-04-2003 08:10 AM


All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration