c++ - Pthreads problem and a few questions -


  contains # lt; Pthread.h & gt; #to & lt include, stdio.h & gt; #to & lt include, stdlib.h & gt; #to & lt include, time.h> #define NUM_THREADS 8 characters * message [NUM_THREADS]; Straight thread_data {int thread_id; Int sum; Four * messages; }; Straight thread_data thread_data_array [NUM_THREADS]; Zero * Printholdo (Zero * Threadgate) {int taskid, sum; Char * hello_msg; Straight thread_data * my_data; Sleep (1); My_data = (thread thread_data *) threadarg; Tasked = my_data- & gt; Thread_id; Sum = my_data-> Yoga; Hello_msg = my_data-> message; Printf ("thread% d:% s sum =% d \ n", tasked, hello_ms, yoga); Pthread_exit (zero); } Int main (int argc, char * argv []) {pthread_t thread [NUM_THREADS]; // int * tasks [NUM_THREADS]; Int RC, T, Yoga; Yoga = 0; Message [0] = "English: Hello World!"; Message [1] = "French: Bonjour, le Monde!"; Message [2] = "Spanish: Whole al Mundo"; Message [3] = "Klingon: Nook Neha!"; Message [4] = "German: guten tag, well!"; Message [5] = "Russian: Zdravski, Mir!"; Message [6] = "Japan: Sekai e Konichiwa!"; Message [7] = "Latin: Orbis, Te Salto!"; For (t = 0; t; NUM_THREADS; t ++) {sum = sum + t; Thread_data_rere [t]. Thread_id = t; Thread_data_ar [t] .sum = sum; Thread_data_rere [t]. Message message = [t]; Printf ("create thread% d \ n", t); RC = Pathgrade_create (and threads [T], tap, printHello, (Zero *) and thread_data_array [T]); If (rc) {printf ("error; pthread_create () return code% d \ n", rc); Exit (-1); }} Pthread_exit (NULL); }  

The above piece of code gives me a split mistake in Linux using GCC

As the beginning, I have some questions about threads.

  1. If 3 threads are created together and if they have to be excluded, then the threads created before it have finally ended?
  2. Whether the O / P is different from thread creation, the termination program and if so why ?? (I have seen that they do this) "

If 3 threads Are they made together and if they have to be eliminated then the thread created before it has finally ended?

Answer: There is no guarantee that the first thread is going out for the first time Once they are made, they are considered by the OS as separate entities and depending on the OS to decide Who will go out first?

Whether O / P can be different each time to create a thread and the closing program and if so why? (I have noticed that they Therefore, they do so;);

Answer: Yes, they do separately, the reason for this is explained above.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -