LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-17-2009, 12:15 AM   #1
liveshell
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Angry pthread_mutex_trylock overwrites global variable


Hi all,

I am new to linux and got problem with pthread_mutex_trylock(). I have used mutex in my code. When I try to call pthread_mutex_trylock() on RECURSIVE type of mutex it overwrites adjacent memory location (that is global variable of type structure say x, memory allocated using malloc()).
Actually I put 'awatch' hardware watch on variable x, when i call pthread_mutex_trylock() it changes variable 2 members of x with message like

0x 0xSomeAdd from libpthread.so.0

and that causes segmentation fault in later part of code...Is it any known issue with pthread?? if you want I can paste complete code here...I have searched enough on libpthread but couldnt find anything specific....

Configurations are
CentOs 5 on VM Workstation

>uname -a

Linux SamCentOs.itpl 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686 i686 i386 GNU/Linux

>rpm -aq | grep libc

glibc-2.5-34
glibc-headers-2.5-34
glibc-common-2.5-34
glibc-devel-2.5-34


>rpm -aq | grep gcc
gcc-c++-4.1.2-44.el5
gcc-4.1.2-44.el5
libgcc-4.1.2-44.el5
gcc-gfortran-4.1.2-44.el5


and the strange thing is the code works fine with following configuration

Linux avSam 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686 i686 i386 GNU/Linux

glibc-2.3.5-10
glibc-devel-2.3.5-10
glibc-common-2.3.5-10
glibc-headers-2.3.5-10
glibc-kernheaders-2.4-9.1.94

libgcc-4.0.0-8
gcc-4.0.0-8
gcc-c++-4.0.0-8
gcc-java-4.0.0-8
 
Old 04-17-2009, 05:02 PM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
Quote:
Is it any known issue with pthread
surrely something you're not doing the right way...
compile your code with -g (I'm assuming you're using GCC) and run your program with "alleyoop" memory checker. It certainly point you the problem.
If you don't find it by yourself, post code here certainly somebody will take look...
 
  


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
Python Global Variable? ElementNine Programming 5 11-05-2007 12:53 PM
Where should I declare the global variable ahm_irf Linux - Kernel 5 05-11-2007 11:36 AM
Define global variable maxmil Linux - Newbie 4 03-07-2006 10:36 AM
How can I define a global variable? kloss Linux - General 4 02-21-2006 04:30 AM
python global variable? goestin Programming 1 01-20-2005 06:52 AM

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

All times are GMT -5. The time now is 11:17 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