TEST6.C
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:1k
- /**************************************************************************/
- /* test6 - shows byte queue tools */
- /**************************************************************************/
- #include "rtos.h"
- #include <stdio.h>
- #include <stdlib.h>
- void *peer = NULL;
- bq_str *bq = NULL; /* byte queue */
- void switcher1(DWORD arg)
- {
- int x;
- int cnt = 1;
- #if defined(__TURBOC__)||defined(__BORLANDC__)
- randomize();
- #else
- srand( time( 0 ));
- #endif
- do {
- putch('.');
- rt_yield();
- x = rand();
- if ( x & 1 ) {
- x = ( x & 255 );
- cprintf( " sending %u (%u)", x, cnt += 5 );
- bq_writebyte( bq, x );
- bq_writebyte( bq, x );
- bq_writebyte( bq, x );
- bq_writebyte( bq, x );
- bq_writebyte( bq, x );
- }
- } while ( 1 );
- }
- void switcher2(DWORD arg)
- {
- int x, cnt, i;
- cnt = 1;
- do {
- rt_yield();
- if ( bq_readbyte( bq , &x ))
- cprintf(" read %u (%u)rn", x, cnt++ );
- else
- cprintf(".");
- } while ( 1 );
- }
- main()
- {
- kdebug = 1;
- rt_init(100);
- bq = bq_alloc( 100 );
- cputs("starting...rn");
- peer = rt_newthread( switcher2, 2,4096, 0, "worker 2" );
- rt_newthread( switcher1, 1,4096, 0, "worker 1" );
- rt_sleep( 10000 );
- }