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

📄 step8.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
字号:

/*
 * Step8:
 * Deadlock detection.
 * Detect deadlock from semaphore
 */

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

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

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

	/* ---
	Do dealock by locking the same mutex twice
	--- */
	PISync *pSync = PIPlatform_allocLocalSemaphore( 2, 2 );	/* 2 slots */
	if ( !pSync )
		{ FAILED(5); return; };

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

	if (!( PISync_lock( pSync ) == PIAPI_COMPLETED ))	/* take 2 == OK */
		{ FAILED(6); 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, Step8 ) )
		{
		cout << "Platform_enter() failed." << endl;
		FAILED(99);
		exit( 1 );
		};

	return iRet;
}

⌨️ 快捷键说明

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