⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testlockqueue.c

📁 用c/c++实现的一个CMPP API
💻 C
字号:
#include "queuelock.h"pthread_t tid1, tid2;void	*thread1( void* ), *thread2( void* );static  recBufFd g_BufFd;#define REPEATNUM 1int main( int argc, char** argv ){	int	nRet;	EBool bBlock = TRUE ;    //EBool bBlock = FALSE ;    	nRet = nLockInitAQueue(  0, 10, 10,  bBlock, &g_BufFd );	DPrintf( "nRet = %d, after nLockInitAQueue\n ", nRet  );		nRet = pthread_create( &tid1, NULL, thread1, NULL );	DPrintf( "nRet = %d, after creat thread1 \n", nRet  );	//		pthread_create( &tid2, NULL, thread2, NULL );	DPrintf( "nRet = %d, after thread2 creat\n ", nRet  );		pthread_join( tid1, NULL );	pthread_join( tid2, NULL );			return 0;	}void *thread1( void* arg ){	int	nRet;	int	i;	char sKey[10];	int nCellNum;	int nLoad;		memset( sKey, 0, 10 );	strcpy( sKey, "012345" );		sleep( 4 );		for( i=0; i<REPEATNUM; i++ )	{	    DPrintf( "before lockwrite\n" );		nRet = nLockWriteQueue( &g_BufFd, sKey, 10 );		DPrintf( "nRet =  %d after nWrite\n", nRet );	}	DPrintf( "before nLockGetQLoad	\n" );	nRet = 	nLockGetQLoad( &g_BufFd, &nLoad, &nCellNum );	DPrintf( "nRet = %d,nCellNum = %d, nLoad = %d\n", 	          nRet, nCellNum, nLoad );				return ( NULL );}void *thread2( void* arg ){	int	nRet;	char sKey[10];	int i;			sleep( 1 );	for( i=0; i<REPEATNUM; i++ )	{        memset( sKey, 0, 10 );            	DPrintf( "before lock read\n" );    	nRet = nLockReadQueue( &g_BufFd, sKey, 10, 5 );    	DPrintf( "nRet = %d,after read\n", nRet );    	DPrintf( "sKey=%s\n", sKey );	}			return ( NULL );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -