c - Using a String array in a thread function -


I am trying to overcome an array of thread function so that access to the array function. At the moment it is just the name of the thread.

  const char * a [2]; Char * s = "thread 1"; Four * r = "thread 2"; A [0] = s; A [1] = r; Pthread_create (& amp; amp; T, tap, Andhandlr, (void *) A [0]); Pthread_create (& amp; y, NULL, Bihandlr, (void *) [1]);   

The intention is to write to make such

  pthread_create (& amp; amp; t, Null, oddhandler, & amp; a;); Pthread_create (& amp; y, NULL, toohandler, & amp; a);   

How do I re-write this function to accommodate this change?

  static void * Azibkilaht (void * p) {char * Q = (char *) p; Printf ("% s is ready. \ N", q); Sigset_t set; Int sig = SIGUSR1; Sigemptyset (& amp; set); Signset (and set, SIGUSR1); While (1) {/ * Wait SIGUSR1 * / sigwait (and set, and SIG); Printf ("% s got a SIGUSR1! \ N", q); } Return ((zero *) faucet); }    

You can try pairing thread IDs with thread data: typed thread thread_info {int thread_id; // different threads for each thread; / / <>

As your example program, you can create a function, handler, and adjust the thread based on their ID.

  pthread_create (& amp; (T [ID], tap, handlers, and (information [i])); void * handler (void * info) {thread_info * myInfo = (thread_info * ) Information; four * q = ((* four *) myInfo- & gt; thread_data) + myInfo-> gt; thread_id; // rest of function}    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -