LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-16-2003, 10:46 AM   #1
jones507
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Rep: Reputation: 0
Problem with atoi in pthreads


I'm having a unique problem using atoi() or strtol() in a newly created pthread. I have used pthreads extensively in the past, but am new to using them on Linux. We are running Red Hat 8.0.

In a simple Unit Test, I use atoi to convert a numeric string (let's say "36") to an int. This simple line 'num=atoi("36")' works fine in the main process, but the same line of code running in a pthread crashes the process.
The thread is created calling pthread_create and have set the attributes to
inheritsched = EXPLICIT_SCHED
detachstate = CREATE_JOINABLE
scope = SCOPE_SYSTEM
sched_policy = SCHED_FIFO
priority = 20

After a cout in the new thread just to show that is was created, I call num=atoi("36") and I get a segmentation fault. Using the debugger has been no help.

The problem orinally arose when we were trying to read in an environment setting and converting it, but now we are down to this very simple test to figure out our problem.

Thanks
 
Old 10-16-2003, 02:42 PM   #2
jones507
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Original Poster
Rep: Reputation: 0
I have found my issue, although I don't understand why it had an affect.

I was linking with the -static option on the g++ compiler, so that it would link with libpthread.a instead of libpthread.so. Once I removed the -static option, the code worked fine.

Any ideas on why the -static option would cause this?
 
  


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
pthreads ftgow Linux - Software 0 07-08-2004 03:55 AM
Problem with huge number of pthreads Berng Programming 7 12-17-2003 07:33 AM
pthreads Keith Hampton Linux - Software 1 10-23-2003 01:46 PM
pthreads h/w Programming 5 10-09-2003 11:11 AM
convert integer to string (atoi?) lea Programming 6 10-11-2002 05:16 PM


All times are GMT -5. The time now is 10:32 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration