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 |
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? |
All times are GMT -5. The time now is 03:32 AM. |