Pthread_create Segmentation Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack pthread_create segmentation fault (core dumped) Overflow the company Business Learn more about hiring developers or posting ads with us
Pthread Mutex Segmentation Fault
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Pthread_join Segmentation Fault
community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up pthread (segmentation fault) up vote 4 down vote favorite 3 I'm Korean and I'm not
Pthread_create C
good at English but if you give me a comment down there I will be very pleased and will try to understand it. I created, for example, 10 threads and tried to join them after creation and return the value. But when I join the last thread, I get a segmentation fault. The result comes out like this.. Before Thread 1 create After Thread 1 create Before Thread 0 create After pthread_create example Thread 0 create Before Thread 1 join After Thread 1 join Before Thread 0 join Segmentation Fault(core dumped) when I create 4 threads it's like Before Thread 3 create After Thread 3 create Before Thread 2 create After Thread 2 create Before Thread 1 create After Thread 1 create Before Thread 0 create After Thread 0 create Before Thread 3 join After Thread 3 join Before Thread 2 join After Thread 2 join Before Thread 1 join After Thread 1 join Before Thread 0 join Segmentation Fault(core dumped) I can't seem to find why. #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/8018272/pthread-segmentation-fault only takes a minute: Sign up Pthread segmentation fault up vote 1 down vote favorite The following code has written in c++ to run an odd-even sort with two threads. I received a segmentation error at the execution. I tried with gdb with break points at line 55, 57 and 62. But the segmentation error jumped after those break points. http://stackoverflow.com/questions/22281181/pthread-segmentation-fault Can't figure out where the error is. #include Today's Posts Advanced Search Find the answer to your Linux question: Entire Site Articles Downloads Forums Linux Hosting Forum GNU Linux Zone Programming / Scripting pthread_create http://www.linuxforums.org/forum/programming-scripting/102460-pthread_create-segmentation-fault.html - segmentation fault If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the http://idevapps.com/forum/showthread.php?tid=2661 register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be segmentation fault displayed. ** Linuxforums now supports the Tapatalk app for your mobile device. Results 1 to 8 of 8 Thread: pthread_create - segmentation fault Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Enjoy an ad free experience by logging in. Not a member yet? Register. 09-04-2007 #1 vijiambav View Profile pthread_create segmentation error View Forum Posts Private Message View Articles Just Joined! Join Date Sep 2007 Posts 11 pthread_create - segmentation fault hi, I've got a problem in using pthread_create(). I'm using Linux OS, version is 2.6.18. I wrote a C program: #include 1 2 Next » Thread Rating: 0 Votes - 0 Average 1 2 3 4 5 Threaded Mode | Linear Mode Segmentation fault with pthreads DJBlufire Unregistered Post: #1 Segmentation fault with pthreads Code: void ProxSocket::SocketLoop(void)
{
...
}
pthread_create( SckThread, NULL, (void*)&ProxSocket::SocketLoop, NULL ) I get a segfault after running pthread_create... any ideas as to why? 2003.07.26 09:38 PM OneSadCookie Genius Bar Posts: 2,154 Joined: Feb 2005 Post: #2 Segmentation fault with pthreads Well, a backtrace would help, but my guess is that it's because you're passing NULL for this. Your SocketLoop() function should return void*, too, though that's unlikely to be the problem. You shouldn't have to cast the third argument to pthread_create(). If you do, that's a good sign you're doing something wrong 2003.07.26 09:58 PM DJBlufire Unregistered Post: #3 Segmentation fault with pthreads In tutorials it says to pass pthread_attr_default as the second parameter, but this is undefined, and is nowhere in pthread.h. Instead in the header it says to pass NULL for default attributes. 2003.07.26 10:18 PM OneSadCookie Genius Bar Posts: 2,154 Joined: Feb 2005 Post: #4 Segmentation fault with pthreads NULL for the second parameter is fine. It may or may not be OK for the last parameter (the argument to the thread's main function) depending on what precisely that function does. In the case where you're using a C++ member function as the thread function, passing NULL is almost certainly not OK. You'd expect this to crash: Code: ((ProxSocket*)NULL)->SocketLoop(); That's precisely what you're doing, except you're doing it in a new thread. 2003.07.26 10:23 PM DJBlufire Unregistered Post: #5 Segmentation fault with pthreads ohhhh... I think that is definately the problem. I thought the fourth parameter was for an argument to the function called in the thirdparameter, so I thought it was similar to calling SocketLoop(NULL) or something. So I should use "this" as the fourth argument? That doesn't seem to work either... 2003.07.26 10:26 PM OneSadCookie Genius Bar Posts: 2,154 Joined: Feb 2005 Post: #6 Segmentation fault with pthreads There's also no guarantee that C++ member functions use the same ABI as "free" functions (they don't on Windows IIRC), so it's not really safe to use a C++ member function in this context.