TEST5.C
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:1k
- /**************************************************************************/
- /* test5 - 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;
- #if defined(__TURBOC__)||defined(__BORLANDC__)
- randomize();
- #else
- srand( time( 0 ));
- #endif
- do {
- rt_yield();
- x = rand();
- if ( x > 25000 ) {
- x = ( x & 255 );
- cprintf( " sending %u ", x );
- 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;
- do {
- rt_yield();
- cnt = bq_readcount( bq );
- if ( cnt == 0 ) cprintf(".");
- else for ( i = 0 ; i < cnt ; ++i ) {
- if ( bq_readbyte( bq , &x ))
- cprintf(" read %u rn", x );
- }
- } 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 );
- }