I need to run two separate processes simultaneously. One is just listening on port X, and sends data when it receives sth, the second one is doing some other stuff.
Ive tried this:
pthread_t thread1, thread2;
int iret1, iret2;
iret1 = pthread_create( &thread1, NULL, getAddress(), NULL);
iret2 = pthread_create( &thread2, NULL, operate(), (struct IPlist) *IPlist);
In the first one I would like to run get(Address) – the listening and sending part, in the second one I need to run operate() with one arg: *IP list //(struct IPlist *IPlist)
BUT, it shows errors:
warning: passing argument 3 of ‘pthread_create’ makes pointer from integer without a cast
/usr/include/pthread.h:225: note: expected ‘void * (*)(void *)’ but argument is of type int
error: incompatible type for argument 4 of ‘pthread_create’
/usr/include/pthread.h:225: note: expected ‘void * __restrict__’ but argument is of type ‘struct IPlist’
What is wrong here?
I do not really understand the manual, so I am asking here.
Thanks for any help!!
Use
getAddressandoperateinstead ofgetAddress()andoperate()when callingpthread_create. You have to supplyfunctionsinstead of their return values.You also need to supply your data to these threads through the last argument. It should go like this:
And your functions should be like:
If your program keeps stalling, be sure to check out
pthread_mutexobjects.