Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
error al corre el programa
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Spanish
View previous topic :: View next topic  
Author Message
silvered
n00b
n00b


Joined: 05 Aug 2012
Posts: 11

PostPosted: Tue Aug 07, 2012 11:11 pm    Post subject: error al corre el programa Reply with quote

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);
}
Back to top
View user's profile Send private message
afb
n00b
n00b


Joined: 13 Oct 2007
Posts: 65

PostPosted: Wed Aug 08, 2012 10:17 pm    Post subject: Reply with quote

El error está en la función:

void delay(unsigned n)
{
for (unsigned i=0; i<n; i++)i
for(unsigned j=0; j<n; j++);
}

Esa i o bien está de más o le falta un ;

Después de este cambio compila OK.

No olvides enlazarlo con la biblioteca pthread
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Spanish All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum