Skip to contentSkip to conversation

thread programming

DISCUSSION MuthuKumar 2 participants 2 messages Apr 2, 2004

lore
Share & tools
lore

MuthuKumar

author
#0 lore raw

Hai All.

I have tried the basic thread program as

#include <stdio.h>
#include <pthread.h>
#include <errno.h>

void *fun()

{
        printf("Hai\n");
        pthread_exit((void *)8);
}

main()
{
pthread_t t[10];
int res,ret;
int i=0,loop=10;
for(i=0;i<loop;i++)
{
t[i]=(pthread_t)malloc(sizeof(pthread_t));
res=pthread_create(&t[i],NULL,fun,NULL);
ret=pthread_join(t[i],(void *)res);
free(t[i]);
}
}

Is it a good way of programming. Or any other effective to do this basic program.

Thanks for the Reply!
--
Regards,
Muthukumar.

---
Status of a mail from <172.16.1.46 | 00-0B-CD-2A-98-69> Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.648 / Virus Database: 415 - Release Date: 3/31/2004

#1 lore raw

I seriously believe you need a C programming book before you delve into threads.

Uday K Verma
//

Hai All.

I have tried the basic thread program as

#include <stdio.h>
#include <pthread.h>
#include <errno.h>

void *fun()

{
        printf("Hai\n");
        pthread_exit((void *)8);
}

main()
{
pthread_t t[10];
int res,ret;
int i=0,loop=10;
for(i=0;i<loop;i++)
{
t[i]=(pthread_t)malloc(sizeof(pthread_t));
res=pthread_create(&t[i],NULL,fun,NULL);
ret=pthread_join(t[i],(void *)res);
free(t[i]);
}
}

Is it a good way of programming. Or any other effective to do this basic program.

Thanks for the Reply!
--
Regards,
Muthukumar.

---
Status of a mail from <172.16.1.46 | 00-0B-CD-2A-98-69> Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.648 / Virus Database: 415 - Release Date: 3/31/2004

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html