The function needs to have a void* pointer as argument and must return a void* pointer ( void* can be interpreted as a pointer to anything ). In this case the function prototype is predefined. Include it to enable thread support for your C programĮach thread executes a function. The – lpthread at the end to link the pthread library Pthread_create(&t2,NULL,say_hello,"hello from 2") Pthread_create(&t1,NULL,say_hello,"hello from 1") They can work like two or more processes sharing the same address space ie they will work independently like processes but can share the same global variables.They are mostly used when two tasks can be done independently without depending much on each other.As an example your IM client might launch one thread for each conversation ( if I am talking to A and B, the two conversations are totally computationally independent from each other ). Threads are often described as light-weight processes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |