int main(void) {
    Thread t1(philosopher, (void *) 0);
    Thread t2(philosopher, (void *) 1);
    Thread t3(philosopher, (void *) 2);
    Thread t4(philosopher, (void *) 3);
    philosopher((void *) 4);
}
Example #2
0
void		stop_philo(pthread_t *threads)
{
	t_philo	*list;
	int		i;

	list = (t_philo *)philosopher((void *)-1);
	i = 0;
	while (i < 7)
		pthread_join(threads[i++], NULL);
	destroy(list);
}
int diningphilosopher()
{
	status= shmat(shmid, (void *)0, 0);
	
	for(int i=0;i<N;i++)
		{
		createsem(i);
		}

for(int i=0;i<N; i++)
		
		{
		// All the philosophers are thinking initially
		status[i]=THINKING;
		}


for(int i=0;i<N;i++)
	
		{
			int a =fork();
				if(a!=0)
					{
					
					// I am in the parent 
					
					}
				else
			       {
					down(i);
					philosopher(i);
					printf("status of philosopher %d = %d\n", i+1, status[i]);
					}

		}
		
		return 0;
		
		} // end of dining philosopher function