Questions tagged [pthread-exit]

The pthread_exit() function terminates the calling thread and returns a value via retval that (if the thread is joinable) is available to another thread in the same process that calls pthread_join.

The pthread_exit() function terminates the calling thread and returns a value via retval that (if the thread is joinable) is available to another thread in the same process that calls pthread_join.

http://man7.org/linux/man-pages/man3/pthread_exit.3.html

29 questions
2
votes
1 answer

Call join child pthread in main function

I have the test code: #include #include #include pthread_t th_worker, th_worker2; void * worker2(void *data) { for(int i = 0; i< 1000000; i++){ printf("thread for worker2----%d\n", i); …
Thtam
  • 21
  • 1
  • 5
1
vote
2 answers

Thread termination with pthread_exit followed by return - Strange example

I found this example; here the two threads threadDefault and threadCustomized are terminated by using pthread_exit followed by return. Why did the author write both instructions?
Gennaro Arguzzi
  • 769
  • 1
  • 14
  • 27
1
vote
1 answer

Error reading returned value from passing struct pointer to pthread_exit() in C

I'm trying to pass pointers to struct lower_hyper_id from a thread to the main thread, by the means of pthread_exit() function, that would compare and output the value in the struct. However, i receive an error (Segmentation fault) when i am trying…
Diogo Soares
  • 130
  • 2
  • 8
1
vote
2 answers

Close a thread based on a variable value from calling thread

I am using posix threads in C. I have two threads in my program, thread1 and thread2. thread1 starts thread2. thread1 maintains a variable var1 based on which thread2 has to be exited safely. thread2 calls many lengthy functions (whose runtime can…
mk09
  • 313
  • 2
  • 9
1
vote
3 answers

pthread_exit(NULL); not working

This is my code for creating some threads. I want create 500 threads in the same time, not more. Easy, but my code failed after 32xxx threads created. Then I don't understand why I get the error code 11 after 32751 threads, because, each thread…
christophe
  • 27
  • 1
  • 5
1
vote
2 answers

how to save a thread stack before it exits?

I'm working on a multi-threading project and I need to make a copy of a thread's stack at some point in code (I need a pointer to that). because I'm going to need that pointer after this thread is exited (and it's stack is freed). It would also do…
zmeftah
  • 148
  • 1
  • 2
  • 10
0
votes
1 answer

what's the meaning of "(void *)2" in c code?

I recently read a book about how to write code in unix environment.There is an expample code making me very confused. The example code: #include "apue.h" #include void * thr_fn1(void *arg) { printf("thread 1 returning\n"); return…
JasonZhang
  • 68
  • 1
  • 10
0
votes
0 answers

How to safely end threads and get back to main?

I'm trying to write multithread program to calculate usage of processor. The problem is that i don't know how to safely end threads. I have to end them by signal SIGTERM and I tried while(flag), phread_exit(), exit(), return(void*)0 but non of them…
ulanny
  • 1
0
votes
1 answer

Why does one of my ways of passing retval (void *) to pthread_exit() give unexpected results?

Today is my first day working with threads. I am struggling to understand why I am unable to pass the retval (type: void *) in both of the following ways below (i.e., only one way will give expected results as I illustrate/describe below). I will…
jvwm
  • 3
  • 1
0
votes
0 answers

How to kill the pthread in certain condition

When i create three p_thread-> pt1, pt2, pt3, if pt2 achieve some condition such as global variable = 100 than I need to kill pt3 thread, Is it use pthread_exit() and pthread_join() or pthread_cancel() and pthread_testcancel()?
albert
  • 1
  • 1
0
votes
0 answers

Can you get the return value of a thread if it exited before you call join?

If you have a thread A which calls pthread_exit(return_val) before thread B can call pthread_join(A, ret_val_A), what is the outcome? Does join return as if the thread did not exist? Clarification: Im not asking if you can join once a thread has…
beans
  • 31
  • 5
0
votes
0 answers

how to handle pthread_kill to exit program normally

When I am giving a sleep of 1 second then i am getting a usual exit but when i comment out sleep(1) and compile and run the program i get getting killed why is that ? I know giving sleep is not the right way ,i want to know how to deal a scenario…
Learner09
  • 9
  • 1
  • 5
0
votes
1 answer

pthread_exit() and pthread_join() don't work

I don't know why it doesn't return the value that I type in. I know it's not the void* arg because it prints the right number, but I don't have any idea. CODE: #include #include #include #include #include…
0
votes
0 answers

Pthreads and QT

I have a issue, where I need the GUI from QT Designer to give values to a separate program running from terminal where the values from the GUI are "printed" onto the terminal interface (Linux with GCC compiler) I have researched pthreads, but their…
0
votes
1 answer

terminate called without an active exception when calling pthread_exit in segmentation fault handler

How are you? I am going to fix the segmentation fault in a worker thread on Ubuntu 18.04. My code is the following. #include #include #include #include #include void…
Jin Yang
  • 3
  • 3
1
2