![]() ![]() How to compile: $ gcc -pthread -o hello hello.cĪ pointer to a concrete data type, converted to void *, can be used to pass values to and return results from the thread function. * This makes the main thread wait on the death of t1 and t2. Pthread_create(&t2, NULL, &thread_func, &j) Pthread_create(&t1, NULL, &thread_func, &i) * Create 2 threads t1 and t2 with default attributes which will executeįunction "thread_func()" in their own contexts with specified arguments. Printf("I am thread #%d\n", *(int *)arg) Pthread_join(thread, NULL) /*wait until the created thread terminates*/įprintf("%s\n", strerror(createerror), stderr) If (!createerror) /*check whether the thread creation was successful*/ *creates a new thread with default attributes and NULL passed as the argument to the start routine*/ Int createerror = pthread_create(&thread, NULL, threadfunction, NULL) Printf("Hello, World!\n") /*printf() is specified as thread-safe as of C11*/ It has one void* parameter and returns void */ * function to be run as a thread always must have the same signature: Minimal "Hello World" with pthreads #include ![]() Installation or Setupĭetailed instructions on getting pthreads set up or installed. Since the Documentation for pthreads is new, you may need to create initial versions of those related topics. It should also mention any large subjects within pthreads, and link out to the related topics. This section provides an overview of what pthreads is, and why a developer might want to use it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |