www.es-minix.org Forum Index www.es-minix.org
Foros de discusión en español, sobre el sistema operativo Minix
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ejemplo de protothreads semaforos(PROBANDO)

 
Post new topic   Reply to topic    www.es-minix.org Forum Index -> Administración de procesos
View previous topic :: View next topic  
Author Message
damaya
Usuario


Joined: 23 Jul 2006
Posts: 12

PostPosted: Wed Sep 27, 2006 12:02 am    Post subject: Ejemplo de protothreads semaforos(PROBANDO) Reply with quote

Haciendo que las cosas funcionen...

Code:

#include "pt-sem.h"
#include <stdio.h>
int x;
int flag1;
int flag2;static struct pt_sem s1,s2;
PT_THREAD(proceso_a(struct pt *pt)){
   int i;
   PT_BEGIN(pt);
   for(i=0;i<99999;i++){
      PT_SEM_WAIT(pt,&s1);
      x=x+1;
      PT_SEM_SIGNAL(pt,&s2);
   }
   PT_END(pt);
}
PT_THREAD(proceso_b(struct pt *pt)){
   int i;
   PT_BEGIN(pt);
   for(i=0;i<99999;i++){
      PT_SEM_WAIT(pt,&s2);
      printf("%d ",x);
      PT_SEM_SIGNAL(pt,&s1);
   }
   PT_END(pt);
}


void main(){
   static struct pt pt_a, pt_b;
   int i;
   PT_SEM_INIT(&s1, 0);
   PT_SEM_INIT(&s2, 1);
   flag1=0;
   flag2=1;
   x=0;
   PT_INIT(&pt_a);
   PT_INIT(&pt_b);
   for(i=0;i<122;i++){
      proceso_b(&pt_b);
      proceso_a(&pt_a);
   }
}
Back to top
View user's profile Send private message
efutch
Administrador


Joined: 04 Jun 2006
Posts: 257
Location: Tegucigalpa, Honduras

PostPosted: Wed Sep 27, 2006 4:57 pm    Post subject: Reply with quote

Tome nota de lo que dice la documentación de ProtoThreads:

Quote:

Local variables are not preserved.
A protothread runs within a single C function and cannot span over other functions. A protothread may call normal C functions, but cannot block inside a called function.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.es-minix.org Forum Index -> Administración de procesos All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group