Note that there are some explanatory texts on larger screens.

plurals
  1. POPthread passing arguments
    primarykey
    data
    text
    <pre><code>char buff[MAX_SIZE]; int main() { pthread_t thread[3]; char message1 = 17; //17 = 0x11 char message2 = 18; char message3 = 19; char message4 = 20; int iret[3]; int k; char message[] = {17, 18,19,20}; /*THIS IS WORKING iret[0] = pthread_create( &amp;thread[0], NULL, write_to_buffer, (void*) &amp;message1); iret[1] = pthread_create( &amp;thread[1], NULL, write_to_buffer, (void*) &amp;message2); iret[2] = pthread_create( &amp;thread[2], NULL, write_to_buffer, (void*) &amp;message3); iret[3] = pthread_create( &amp;thread[3], NULL, write_to_buffer, (void*) &amp;message4); */ /* BUT THIS IS NOT iret[0] = pthread_create( &amp;thread[0], NULL, write_to_buffer, (void*) message); iret[1] = pthread_create( &amp;thread[1], NULL, write_to_buffer, (void*) (message+1)); iret[2] = pthread_create( &amp;thread[2], NULL, write_to_buffer, (void*) (message+2)); iret[3] = pthread_create( &amp;thread[3], NULL, write_to_buffer, (void*) (message+3)); */ for(k=0;k&lt;=3;k++) { pthread_join( thread[k], NULL); } //rest of main } void *write_to_buffer( void *ptr ) { while(1) { pthread_mutex_lock(&amp;my_mutex); char *message; message = (char *) ptr; //when passing by array I'm unable to get the value in the message variable printf("\nMeeee = %#x ", *(char*)ptr); //REST OF THE FUNCTION //logic to write to buffer pthread_mutex_unlock(&amp;my_mutex); //SOME LOGIC I OMMITED HERE //to return if(indexx &gt;= MAX_SIZE) return(NULL); } } </code></pre> <p>the problem i'm facing is that when i'm passing the array element i'm unable to capture the value in the thread function. but when i'm passing address of message1, message2, message3, and message4 i'm able to get the value passed in thread function </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload