step6.cpp

来自「mini http server,可以集成嵌入到程序中,实现简单的web功能」· C++ 代码 · 共 56 行

CPP
56
字号

/*
 * Step6:
 * Deadlock detection.
 * Detach deadlock from mutex.
 */

#include <iostream.h>
#include <stdlib.h>

#include "PiAPI.h"
#include "TestOS.h"

int iRet;
void Step6()
{
	iRet = -1;

	/* ---
	Do dealock by locking the same mutex twice
	--- */
	PISync *pSync = PIPlatform_allocLocalMutex();		/* mutex has 1 slot */
	if ( !pSync )
		{ FAILED(5); return; };

	if (!( PISync_lock( pSync ) == PIAPI_COMPLETED ))	/* take 1 == OK */
		{ FAILED(1); goto done; };

	if ( PISync_lock( pSync ) == PIAPI_ERROR ) /* another=deadlock */
		{
		if ( PIPlatform_getLastError() != PIAPI_DEADLOCK )
			{ FAILED(4); goto done; };
		}
	else
		{ FAILED(2); goto done; };

done:
	if ( PISync_delete( pSync ) ) { FAILED(3); };

	OK;
	iRet = 0;
}

int main()
{
	if ( PIPlatform_enter( "dummy", PIPLATFORM_VERSION_1_0, Step6 ) )
		{
		cout << "Platform_enter() failed." << endl;
		FAILED(99);
		exit( 1 );
		};

	return iRet;
}

⌨️ 快捷键说明

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