Browse Source

examples fixed

pull/1/head
Rafael Zurita 6 years ago
parent
commit
33fabb96fa
  1. 4
      apps/example2/main.c
  2. 13
      apps/example3/main.c
  3. 4
      apps/example4/main.c
  4. 21
      apps/example5/main.c
  5. 2
      config/Configuration

4
apps/example2/main.c

@ -10,8 +10,8 @@ void sndA(void), sndB(void);
*/
void main(void)
{
resume( create(sndA, 1024, 20, "process 1", 0) );
resume( create(sndB, 1024, 20, "process 2", 0) );
resume( create(sndA, 128, 20, "process 1", 0) );
resume( create(sndB, 128, 20, "process 2", 0) );
}
/*------------------------------------------------------------------------

13
apps/example3/main.c

@ -2,7 +2,7 @@
#include <xinu.h>
void sndch(char);
void sndch(int nargs, char *args[]);
/*------------------------------------------------------------------------
* main -- example of 2 processes executing the same code concurrently
@ -10,18 +10,19 @@ void sndch(char);
*/
void main(void)
{
resume( create(sndch, 1024, 20, "send A", 1, 'A') );
resume( create(sndch, 1024, 20, "send B", 1, 'B') );
resume( create(sndch, 128, 20, "send A", 1, 'A') );
resume( create(sndch, 128, 20, "send B", 1, 'B') );
}
/*------------------------------------------------------------------------
* sndch -- output a character on a serial device indefinitely
*------------------------------------------------------------------------
*/
void sndch(
char ch /* character to emit continuously */
)
void sndch(int nargs, char *args[])
{
char ch = args[0]; /* character to emit continuously */
while ( 1 )
putc(CONSOLE, ch);
}

4
apps/example4/main.c

@ -12,8 +12,8 @@ int32 n = 0; /* external variables are shared by all processes */
*/
void main(void)
{
resume( create(consume, 1024, 20, "cons", 0) );
resume( create(produce, 1024, 20, "prod", 0) );
resume( create(consume, 256, 20, "cons", 0) );
resume( create(produce, 256, 20, "prod", 0) );
}
/*------------------------------------------------------------------------

21
apps/example5/main.c

@ -2,7 +2,8 @@
#include <xinu.h>
void prod2(sid32, sid32), cons2(sid32, sid32);
void prod2(int nargs, char *args[]);
void cons2(int nargs, char *args[]);
int32 n = 0; /* n assigned an initial value of zero */
@ -16,19 +17,18 @@ void main(void)
consumed = semcreate(0);
produced = semcreate(1);
resume( create(cons2, 1024, 20, "cons", 2, consumed, produced) );
resume( create(prod2, 1024, 20, "prod", 2, consumed, produced) );
resume( create(cons2, 256, 20, "cons", 2, consumed, produced) );
resume( create(prod2, 256, 20, "prod", 2, consumed, produced) );
}
/*------------------------------------------------------------------------
* prod2 -- increment n 2000 times, waiting for it to be consumed
*------------------------------------------------------------------------
*/
void prod2(
sid32 consumed,
sid32 produced
)
void prod2(int nargs, char *args[])
{
sid32 consumed = args[0];
sid32 produced = args[1];
int32 i;
for( i=1 ; i<=2000 ; i++ ) {
@ -42,11 +42,10 @@ void prod2(
* cons2 -- print n 2000 times, waiting for it to be produced
*------------------------------------------------------------------------
*/
void cons2(
sid32 consumed,
sid32 produced
)
void cons2(int nargs, char *args[])
{
sid32 consumed = args[0];
sid32 produced = args[1];
int32 i;
for( i=1 ; i<=2000 ; i++ ) {

2
config/Configuration

@ -118,4 +118,4 @@ FIN DE RAFA */
/* Configuration and Size Constants */
#define NPROC 4 /* number of user processes */
#define NSEM 2 /* number of semaphores */
#define NSEM 4 /* number of semaphores */

Loading…
Cancel
Save