LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 11-05-2006, 08:57 AM   #1
naihe2010
Member
 
Registered: Oct 2005
Location: China
Distribution: ArchLinux
Posts: 103

Rep: Reputation: 15
what should I be care of multi-threads C program


Hi, I am writing a multiple threads C program. And, when I start the program, it often gets some GLIBC-detected memory errors. But, they are not at every time I start it.

Who can give me some advice?
 
Old 11-05-2006, 09:11 AM   #2
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
Try using a profiler and a debugger.
 
Old 11-05-2006, 12:37 PM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Who can give me some advice?
yeh heres some advice. post the errors you get.
 
Old 11-05-2006, 07:43 PM   #4
naihe2010
Member
 
Registered: Oct 2005
Location: China
Distribution: ArchLinux
Posts: 103

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by xhi
yeh heres some advice. post the errors you get.
like:
*** glibc detected *** corrupted double-linked list: 0x0805beb8 ***
Aborted
 
Old 11-05-2006, 09:36 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You might be able to get rid of the message by setting this before you run the program:
Quote:
export MALLOC_CHECK_=0
This will NOT fix the underlying problem - it will just mask the symptoms. Your code (or some library your code is using) will still have a very serious bug in it. But if you try it, and the error goes away - that would definitely be useful information.

Look at all your "malloc()" statements, and where you use "malloc'ed" memory.

Here is one example of the kind of bug that can cause this error:
Code:
  // !!! BAD CODE: guaranteed to cause problems!!!!
  char *c = malloc (strlen ("abc"));
  strcpy (c, "abc");
Here is how you might improve this example:
Code:
  // Much better!
  char *c = NULL;   // Always initialze your pointers to NULL!!!
  c = malloc (strlen ("abc") + 1);  // Never forget to allocate space for the NULL byte
                                    // at the END of strings!
                                    // For example, be sure you allocate *4* bytes for a 3-character string!
  if (!c)           // Always check the return from "malloc()"
  {
    perror ("UNABLE TO ALLOC STRING!");
    abort ();       // Calling "abort()" (and leaving a well-debugable core dump)
                    // is often times BETTER than trying to "recover"
  }
  else
    strcpy (c, "abc");
You can read more about your "*** glibc detected *** corrupted double-linked list: 0x0805beb8 ***" error and $MALLOC_CHECK_ here:

http://www.gnu.org/software/libc/man...-Checking.html

'Hope that helps .. PSM

PS:
Valgrind is a very helpful tool:
http://www.valgrind.org

Last edited by paulsm4; 11-05-2006 at 09:37 PM.
 
  


Reply



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
Install multi-disk program jbumgar Linux - Games 4 09-07-2006 03:27 PM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
how can multi program share one sound card duzhenhuan Linux - Hardware 1 04-11-2004 08:05 AM
my get new threads from the forums perl program dmx9595 Programming 0 09-06-2003 11:28 AM
how to write a program can have 2 threads running at the same time?? man9 Programming 3 10-07-2000 01:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 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
Open Source Consulting | Domain Registration