📄 testevent.c
字号:
#include "general.h"#include "event.h"pthread_t tid1, tid2, tid3;void *thread1( void* ), *thread2( void* ), *thread3( void* );recEvent *g_pEvent[2];#define REPEATNUM 1int main( int argc, char** argv ){ int nRet; nRet = pthread_create( &tid1, NULL, thread1, NULL ); printf( "nRet = %d, after creat thread1 \n", nRet ); // pthread_create( &tid2, NULL, thread2, NULL ); printf( "nRet = %d, after thread2 creat\n ", nRet ); pthread_create( &tid3, NULL, thread3, NULL ); printf( "nRet = %d, after thread3 creat\n ", nRet ); pthread_join( tid1, NULL ); pthread_join( tid2, NULL ); pthread_join( tid3, NULL ); return 0; }void *thread1( void* arg ){ recEvent rEvent; int nRet; int nWaitTime = 5; nRet = nInitEvent(&rEvent); g_pEvent[0] = &rEvent; if ( nRet ) { printf("Init event error=%d\n", nRet); return(NULL); } printf ( "thread 1 Now wait %d second \n", nWaitTime ); nRet = nTimedWaitEvent( &rEvent, nWaitTime); printf("event wait result=%d\n", nRet); nDestroyEvent(&rEvent); printf("thread 1 over.\n"); return ( NULL );}void *thread2( void* arg ){ sleep( 2 ); printf("Now set event 1\n"); nSetEvent(g_pEvent[0]);/* sleep (5); printf("Now set event 1\n"); nSetEvent(g_pEvent[1]);*/ printf("thread 2 over.\n"); return ( NULL );}void *thread3( void* arg ){ recEvent rEvent; int nRet; int nWaitTime = 10; nRet = nInitEvent(&rEvent); g_pEvent[1] = &rEvent; if ( nRet ) { printf("Init event error=%d\n", nRet); return(NULL); } printf ( "thread 3 Now wait %d second \n", nWaitTime ); nRet = nTimedWaitEvent( &rEvent, nWaitTime); printf("event wait result=%d\n", nRet); nDestroyEvent(&rEvent); printf("thread 3 over.\n"); return ( NULL );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -