Home > pthread example > pthreads error

Pthreads Error

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

Pthread Example

About Us Learn more about Stack Overflow the company Business Learn more pthread attributes about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss pthread example c++ Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up compile/link error using

Pthread_create Undefined Reference

pthread up vote 3 down vote favorite I try to make a little program that sorts an array using threads but I can't get it to compile with the thread support. Error: sortieren.c:(.text+0xd7): undefined reference to `ptread_create' I used a make file for easy compiling but also on command line I can't get it to work. Basic code: #include int main(int argc, char **argv)

Pthread_create C

{ pthread_t threads[2]; // code snipped int ret = ptread_create(&threads[0], NULL, threadOne(), NULL); printf("ret: %d\n", ret); // code snipped } Make file: sortieren : sortieren.o gcc sortieren.o sortieren.o : sortieren.c gcc -pthread -c sortieren.c Using make sortieren results in this output gcc -pthread -c sortieren.c gcc sortieren.o sortieren.o: In function `main': sortieren.c:(.text+0xd7): undefined reference to `ptread_create' collect2: ld returned 1 exit status make: *** [sortieren] Fehler 1 Of course I tried to google but every "solution" I found didn't worked for me. I tried -pthread or -lpthread everywhere in my make file. To be sure that I didn't do anything wrong in my code, I also tried a public sample: #include #include #include #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thread #%ld!\n", tid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0;t

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 pthread_join Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs

Pthread_create Function

Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just pthread_attr_t like you, helping each other. Join them; it only takes a minute: Sign up undefined reference to pthread_create in Linux up vote 162 down vote favorite 60 I picked up the following demo off the web from http://stackoverflow.com/questions/6332410/compile-link-error-using-pthread https://computing.llnl.gov/tutorials/pthreads/ #include #include #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thread #%ld!\n", tid); pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0; thttp://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux on my machine (running Ubuntu Linux 9.04) I get the following error: corey@ubuntu:~/demo$ gcc -o term term.c term.c: In function ‘main’: term.c:23: warning: incompatible implicit declaration of built-in function ‘exit’ /tmp/cc8BMzwx.o: In function `main': term.c:(.text+0x82): undefined reference to `pthread_create' collect2: ld returned 1 exit status This doesn't make any sense to me, because the header includes pthread.h, which should have the pthread_create function. Any ideas what's going wrong? c linux multithreading pthreads share|improve this question edited Jan 6 '15 at 17:44 Tshepang 4,7061059103 asked Nov 2 '09 at 18:40 Ralph 1,11441417 3 Additionally: depending on the platform, you may need (a) a different compiler for threads, (b) a different libc for threads (i.e. -lc_r), (c) -thread or -threads or other, instead of or in addition to -lpthread. –ephemient Nov 3 '09 at 1:42 Just a little above that example, you'll see a table of the correct compiler commands, whether it be GCC, IBM, etc. 'Employed Russian' is correct. –Jonathon Reinhart Jun 26 '11 at 6:47 6 Can you please unmark my answer, so that I can delete it (and mark the one that is actually correct, which is the highest-voted one)? –Pavel Minaev Nov 22 '12 at 0:41 1 -lpthread is needed during compile –How Chen Jan 28 '14 at 8:21 1 solution LDFLAGS= -pthread -lpthre

that time the operating system reclaims the process's resources and stores its exit status. Similarly, a thread exits when it comes to the end of the routine in which it was started. http://maxim.int.ru/bookshelf/PthreadsProgram/htm/r_13.html (By the way, all threads expire when the process in which they run exits.) When a thread terminates, the Pthreads library reclaims any process or system resources the thread was using and stores its exit status. A thread can also explicitly exit with a call to pthread_exit. You can terminate another thread by calling pthread_cancel. In any of these cases, the Pthreads library runs pthread example any routines in its cleanup stack and any destructors in keys in which it has store values. We'll describe these features in Chapter 4, Managing Pthreads. Exit Status and Return Values The Pthreads library may or may not save the exit status of a thread when the thread exits, depending upon whether the thread is joinable or detached. A joinable thread, the default state of pthread example c++ a thread at its creation, does have its exit status saved; a detached thread does not. Detaching a thread gives the library a break and lets it immediately reclaim the resources associated with the thread. Because the library will not have an exit status for a detached thread, you cannot use a pthread_join to join it. We'll show you how to dynamically set the state of a thread to detached in Chapter 2, Designing Threaded Programs, when we introduce the pthread_detach call. In Chapter 4, we'll show you how to create a thread in the detached state by specifying attribute objects. What is the exit status of a thread? You can associate an exit status with a thread in either of two ways: If the thread terminates explicitly with a call to pthread_exit, the argument to the call becomes its exit status. If the thread does not call pthread_exit, the return value of the routine in which it started becomes its exit status. As defined by the Pthreads standard, the thread-start routine (specified in the pthread_create call) returns a (void *) type. However, you'll often find that your thread-start routines must return somethin

 

Related content

pthread error

Pthread Error p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the pthread example workings and policies of this site About Us Learn more about Stack Pthread Attributes Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs pthread example c Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join Pthread create Undefined Reference them it only takes a minute Sign