LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 11-29-2007, 02:10 AM   #1
nalsrayatko
LQ Newbie
 
Registered: Nov 2007
Distribution: Slackware 12
Posts: 8

Rep: Reputation: 0
How to debug a multi-threaded program?


Hi all;

I am developing a multi thread program in Eclipse and I have some troubles with debugging. I have written several test programs for debugging, but it is very hard to read the output of the programs. There are too many threads and all of them write their messages to the same console screen, I can't understand which messages are belong to which thread.

Is there anyway to print the output of the different threads/processes to the different console screen?


For example, my program has 4 threads and they print out a message to the stdout. Is there a way to print out threads' messages to the different console screen? (by using pipes, execlp but without using tcp/ip )


Thanks for your helps
Yatko

Last edited by nalsrayatko; 11-29-2007 at 09:08 AM.
 
Old 11-29-2007, 08:39 AM   #2
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 15
Quote:
Originally Posted by nalsrayatko View Post
Hi all;

Is there anyway to print the output of the different threads/processes to the different console screen?
I can't address that, but I usually preface my thread tracing messages with the thread ID, thereby uniquely identifying which thread created the message.

Judy
 
Old 11-29-2007, 09:13 AM   #3
i_grok
Member
 
Registered: Jun 2006
Location: Massachusetts
Distribution: Gentoo
Posts: 79

Rep: Reputation: 16
You can also write each thread's output to a separate file (e.g. threadFile1, threadFile2 ...).

Then open a console window for each thread and run:

Code:
tail -f threadFileX
It's not the fastest option, but it can help.
 
Old 11-29-2007, 01:18 PM   #4
nalsrayatko
LQ Newbie
 
Registered: Nov 2007
Distribution: Slackware 12
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks, I will use "tail" command, untill to find a better and faster way.
 
Old 11-29-2007, 01:57 PM   #5
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 64
One thing I always do with non-quick-script programs I write (even with some), I add in my own debugging, showing the steps and a concise (not necessarily detailed) message telling me what it was trying to do when it failed, or why it failed (in the case I have something like a try-catch block).

Here's an example of what I mean (in pseudocode):
Code:
string program = "foo"

function write-to-stream(stream, message):
   string func = "write-to-stream"
   try:
      print $stream, $message
   catch (ioexception ioex):
      print [STDOUT|STDERR] "$program:$func:Failed to write $message to $stream"

write-to-stream(STDOUT, "hello, world")
Of course, it would be too time-consuming for you too go back and add something like this in now, but this is more or less just a guideline I follow as when I learned to program, it was without mechanisms like try-catch blocks (think QBASIC/QuickBASIC and C) and an method I implemented when I watched my classmates struggle to find the crippling bug in their code.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
GTK multi-threaded application akhil1 Programming 2 01-20-2009 03:59 AM
Debug: threaded app slow on dual core otoomet Programming 2 08-11-2007 02:15 PM
Is MySQL 5 multi-threaded/fork? Swakoo Linux - General 1 05-30-2007 08:37 AM
how to debug multi threaded application sibtay Programming 3 10-15-2004 12:02 PM
Multi-Threaded C pragti Programming 1 06-01-2004 10:50 AM


All times are GMT -5. The time now is 03:24 PM.

Main Menu
 
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
Open Source Consulting | Domain Registration