c multithreading process -


i want write multi threaded program in c language. use posix thread library.

i write following code:

#include<stdio.h> #include<pthread.h>  void *put (int *arg) {     int i;     //int * p;     // p=(int*)arg;     for(i=0;i<5;i++)     {          printf("\n%d",arg[i]);     }     pthread_exit(null); }  int main() {     int a[5]={10,20,30,40,50};     pthread_t s;     pthread_create(&s,null,put,a);     printf("what this\n");     return 0; } 

i want thread show items in array. program compiled following warning:

tm.c:19: warning: passing argument 3 of ‘pthread_create’ incompatible pointer type /usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ argument of type ‘void * (*)(int *)’ 

when run program got out put of main thread not value stored in array.

now can tell me i'm doing wrong? how send array argument in thread function?

if changed code little bit compile time warning resolved changed code following:

#include<stdio.h> #include<pthread.h>   void *put (void *arg) {     int i;     int * p;     p=(int*)arg;     for(i=0;i<5;i++)     {          printf("\n%d",p[i]);     }     pthread_exit(null); }  int main() {     int a[5]={10,20,30,40,50};     pthread_t s;     pthread_create(&s,null,put,a);     printf("what this\n");     return 0; } 

but output not change. can 1 tell me did wrong? proper way send array thread function (put in case)?

your code creates thread , process exits reaching end of main. have wait thread have chance execute, calling pthread_join, or sleeping bit.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -