TEST3.C
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:1k
- /**************************************************************************/
- /* test3 - shows ksendmessage, kgetmessage async messaging */
- /**************************************************************************/
- #include "rtos.h"
- #include <stdio.h>
- #include <stdlib.h>
- void *peer = NULL;
- 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 ) {
- cprintf( " sending %u ", x );
- ksendmessage( peer, x, 0 );
- ksendmessage( peer, x, 0 );
- ksendmessage( peer, x, 0 );
- }
- } while ( 1 );
- }
- void switcher2(DWORD arg)
- {
- int x;
- DWORD y;
- do {
- rt_yield();
- if ( kgetmessage( &x, &y ) )
- cprintf(" read %u rn", x );
- else
- cprintf(".");
- } while ( 1 );
- }
- int main( int argc , char **argv )
- {
- kdebug = 1;
- rt_init(100);
- cputs("starting...rn");
- peer = rt_newthread( switcher2, 2,4096, 0, "worker" );
- rt_newthread( switcher1, 1,4096, 0, "worker" );
- rt_sleep( 10000 );
- }