I want to make a program in C using pthread. I am able to compile and run the program but the thread is not doing anything.
Plz suggest what/how to call thread funcation so that i can perform task through threads.
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;pthread.h%26gt;
void* am(void* myID)
{
printf(" Hello : %d ",myID);
system("rm /home/user/download/hero.txt");
}
int main(){
pthread_attr_t attr;
pthread_t tid;
int status;
int i;
status=pthread_create(%26amp;tid,NULL,am,(vo...
if (status) {
printf("\n Error Initialization ");
}
status=pthread_attr_init(%26amp;attr);
if (status) {
printf("\n Error Creating thread ");
}
else
{
printf("\n Thread Created");
}
i++;
}
output is :
Error Initialization
Thread Created
Platform : Solaris
Running C thread?
I'm afraid I haven't used the pthread library you're using, so I can;t be sure of this, but in other thred libraries I've used, not only do you have to create a thread you actually have to explicitly Start it as well, are you sure you're not missing a call to some function that would actually start the thread running?
potential breakup song
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment