For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > Re: how to solve the philosopher problem .and what's wrong with my









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: how to solve the philosopher problem .and what's wrong with my
Angelo Biboudis

2006-09-28, 8:00 am

DaVinci wrote:
> Only one thread created ,the others doesn't why?


You create pthread_t tid in the loop. You need an array of thread ids
outside the loop.
Here it is. Try it.


pthread_t tid[N];

> int main()
> {
>
> for(int i = 0;i<N;i++)
> {
> forks[i] = (struct Fork*)malloc(sizeof(struct Fork));
> forks[i]->flag = FREE;
> forks[i]->num = i;
> }
>
> for(int i=0;i<N;i++)
> {
>
> pthread_create(tid+i,NULL,(void*)phlosi
,(void*)i);
>
> }
> return 0;
> }
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com