silvered n00b
Joined: 05 Aug 2012 Posts: 11
|
Posted: Tue Aug 07, 2012 11:11 pm Post subject: error al corre el programa |
|
|
no se si alguien me pueda ayudar con este codigo me marca error y no se porque haber si alguien lo peude correguir por mi
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#define N 100000
#define REST(x) usleep(x)
/* Numero de ciclos de los hilos*/
#define M 10000
void *sensing( void *ptr );
void *odometry( void *ptr );
void *longertime( void *ptr );
main()
{ time_t ti, tf; double Dt;
pthread_t thread1, thread2, thread3;
char *message1 = "*";
char *message2 = "+";
char *message3 = "@";
int iret1, iret2, iret3;
/* Crea hilos independientes */
iret1 = pthread_create( &thread1, NULL, sensing, (void*) message1);
iret2 = pthread_create( &thread2, NULL, odometry, (void*) message2);
iret3 = pthread_create( &thread3, NULL, longertime, (void*) message3);
/* Espera hasta los hilos estan completos antes de continuar. */
time(&ti);
pthread_join( thread1, NULL);
pthread_join( thread3, NULL);
pthread_join( thread2, NULL);
time(&tf);
Dt=difftime(tf,ti);
printf( "\n Tiempo total empleado: %.41f\n", Dt/(double)CLOCKS_PER_SEC );
printf("\nTh1 returns: %d\n",iret1);
printf("Th2 returns: %d\n",iret2);
printf("Th3 returns: %d\n", iret3);
exit(0);
}
void delay(unsigned n)
{
for (unsigned i=0; i<n; i++)i
for(unsigned j=0; j<n; j++);
}
void *sensing( void *ptr )
{ unsigned i; double Dt;
time_t ti, tf;
char *message;
message = (char *) ptr;
time(&ti); /****************/
for(i=0; i<M; i++)
{
long d = random();
fputc('a', stderr);
delay(N*2);
}
time(&tf); /****************/
Dt = difftime(tf,ti);
fprintf(stderr, "\n[Dt Hilo A: %.41f]\n", Dt/(double)CLOCKS_PER_SEC );
}
void *odometry( void *ptr )
{ unsigned i; double Dt;
time_t ti, tf;
time(&ti); /**************/
for(i=0; i<M; i++)
{
long d = random();
fputc('b', stderr);
delay(N*2);
}
time(&tf); /************/
Dt = difftime(tf, ti);
fprintf(stderr, "\n[Dt Hilo B: %.41f]\n", Dt/(double)CLOCKS_PER_SEC );
}
void *longertime( void *ptr )
{ unsigned i; double Dt;
time_t ti, tf;
char *message;
message = (char *) ptr;
time (&ti); /**************/
for (i=0; i<M; i++)
{
fputc('c', stderr);
delay(N*2);
}
time(&tf); /*****************/
Dt = difftime(tf,ti);
fprintf(stderr, "\n[Dt Hilo C: %.41f]\n", Dt/(double)CLOCKS_PER_SEC);
} |
|