 |
www.es-minix.org Foros de discusión en español, sobre el sistema operativo Minix
|
| View previous topic :: View next topic |
| Author |
Message |
damaya Usuario
Joined: 23 Jul 2006 Posts: 12
|
Posted: Wed Sep 27, 2006 12:02 am Post subject: Ejemplo de protothreads semaforos(PROBANDO) |
|
|
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 |
|
 |
efutch Administrador
Joined: 04 Jun 2006 Posts: 257 Location: Tegucigalpa, Honduras
|
Posted: Wed Sep 27, 2006 4:57 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|