The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
semaphore raguramtgr UNIX for Dummies Questions & Answers 7 06-15-2009 09:39 AM
Semaphore Jaken Shell Programming and Scripting 2 04-04-2009 05:10 PM
Debugging the JVM Using dbx iBot UNIX and Linux RSS News 0 03-06-2008 07:20 PM
Semaphore vjsony UNIX for Dummies Questions & Answers 3 04-07-2003 02:06 PM
semaphore yls177 UNIX for Dummies Questions & Answers 1 10-08-2002 11:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2007
ptprabu ptprabu is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 6
Semaphore debugging

I'm running one multithreaded application, in that one of my thread
is waiting infinitely in a semphore. Is there a way to determine, in
which semaphore the particular thread is waiting and which thread(s)
is holding the semaphore.
  #2 (permalink)  
Old 11-26-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
If you have a decent thread aware debugger you could check the stack of each thread to see who was blocked on a pthread_mutex_lock, then depending on the operating system and implementation of pthreads on that OS you may be able to find the thread id in the "pthread_mutex_t" structure.

Personally I solve this by using my own version of a pthreads library which lets me add additional tracing and warning of potential deadlocks.
  #3 (permalink)  
Old 11-28-2007
ptprabu ptprabu is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 6
Porter,

In my application semaphores, are not created using any threading library. Semaphores (counting) are created using sema_init. Is there any system calls or functions available to get the semaphores a thread is currently having?
  #4 (permalink)  
Old 11-28-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by ptprabu View Post
Is there any system calls or functions available to get the semaphores a thread is currently having?
Not to my knowledge, these APIs date back to not threaded days.

Do these semaphores have to work between processes?

What platform are you using? Post results of "uname -a".
  #5 (permalink)  
Old 11-28-2007
ptprabu ptprabu is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 6
These semaphores work between threads of a single process. I'm using linux-2.6.14 in PPC architecture..
  #6 (permalink)  
Old 11-28-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
If you are doing synchronisation between threads of the same process then I recommend using pthread APIs to do this. The sem APIs always involve the kernel, but the pthread APIs may be able to avoid kernel involvement for some activities.

An up/down semaphore should be able to be constructed using a pthread_mutex_t and pthread_cond_t pair.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0