当前位置: 首页>>代码示例>>C++>>正文


C++ AcquireLock函数代码示例

本文整理汇总了C++中AcquireLock函数的典型用法代码示例。如果您正苦于以下问题:C++ AcquireLock函数的具体用法?C++ AcquireLock怎么用?C++ AcquireLock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了AcquireLock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: theSafetyLock

void ConcurrencyTest1::TestThread(void)
{
	int i;
	SafetyLock theSafetyLock(theLocker);
	
	for (i = 0; i < MAXLOOP; i++) {
		// Print out 10 sub test markers per thread
		if (i % (MAXLOOP / 10) == 0)
			NextSubTest();
		
		CheckLock(0);
		assert(AcquireLock(i, true));
		
		assert(!lockTestValue);
		lockTestValue = true;
		CheckLock(1);
		
		assert(AcquireLock(i, false));
		CheckLock(2);
		
		theLocker->Unlock();
		CheckLock(1);
		
		assert(lockTestValue);
		lockTestValue = false;
		theLocker->Unlock();
		CheckLock(0);
	}
}
开发者ID:mariuz,项目名称:haiku,代码行数:29,代码来源:ConcurrencyTest1.cpp

示例2: main

int main()
{

	lock = CreateLock("lock");
	cv2 = CreateCV("cv2");
	
	AcquireLock("lock");

	SignalCV("lock","cv2");

	Print("Client 3 will now destroy CV...",-1,-1,-1);
	
	DestroyCV("cv2");
	
	for (i=0; i<9; i++)
		Print("\n",-1,-1,-1);


	ReleaseLock("lock");

	AcquireLock("lock");	
	
	WaitCV("lock","cv2");
	
	Print("Client 3: This prints as CV has been destroyed...",-1,-1,-1);

	ReleaseLock("lock");

	Exit(0);

}
开发者ID:achinksinghal,项目名称:CSCI_402,代码行数:31,代码来源:DistCVTest4_3.c

示例3: main

void main()
{
	lck = CreateLock("lock1");
	cv = CreateCV("cv1");
	Print("\nDistCVTest1_1: Created Lock is %d and CV is %d\n", lck, cv, -1);
	

	AcquireLock("lock1");

	
	Print("Client 1: About to go on wait...\n", -1, -1, -1);

	
	WaitCV("lock1","cv1");

	Print("Client 1: Now out of wait...\n", -1, -1, -1);

	for (num=0; num<10; num++)
		Print("\n",-1,-1,-1);
	
	Print("Client 1: About to signal Client 2\n", -1, -1, -1);
	
	SignalCV("lock1","cv1");

	ReleaseLock("lock1");
	AcquireLock("lock1");


	ReleaseLock("lock1");
	
	Exit(0);
	
	
}
开发者ID:achinksinghal,项目名称:CSCI_402,代码行数:34,代码来源:DistCVTest1_1.c

示例4: otudp_output

void otudp_output(OTUDP *x) {
	// This is called by the Max clock.  It's guaranteed not to be called
	// at notifier level, although if we're in Overdrive this will be called
	// at interrupt level.
	Atom arguments[2];
	PacketBuffer b;
	short oldLockout;

	
	// BufferSanityCheck(x, 0, 0, 0);

	while (1) {
		oldLockout = AcquireLock(x);
		b = PBFIFODequeue(&(x->pendingBuffers));
		ReleaseLock(x,oldLockout);
		
		if (b == 0) break;
		
		SETLONG(&arguments[0], b->n);
		SETLONG(&arguments[1], (long) b->buf);
		outlet_anything(x->o_outlet, ps_FullPacket, 2, arguments);
		
		oldLockout = AcquireLock(x);
		PacketBufferListPush(b, &(x->freeBuffers));
		ReleaseLock(x,oldLockout);		
		
	}
	
	// BufferSanityCheck(x, 0, 0, 0);
}
开发者ID:CNMAT,项目名称:CNMAT-Externs,代码行数:30,代码来源:otudp.c

示例5: monte_carlo_pi

int monte_carlo_pi(unsigned int n, int procNumber) {
	AcquireLock();
	printf("CORE %d\n", procNumber);
	ReleaseLock();
	int in = 0, i;
	int x, y, d;
        int limit;
	
        limit = n*(procNumber + 1)/CORES;
	if (procNumber == CORES - 1) {
		//ultimo core, faz o resto
		limit = n;
	}
	
	
	for (i = n*procNumber/CORES; i < limit; i++) {
		//x = ((*randNum % 1000000)/500000.0)-1;
		x = (((getRandomNumber() % 1000000)/500000)-1)*10;
		y = (((getRandomNumber() % 1000000)/500000)-1)*10;
		//y = ((*randNum % 1000000)/500000.0)-1;
		//x = 1;
		//y = 2;
		d = ((x*x) + (y*y));
		//AcquireLock();
		
		if (d <= 10) {
		  in+=1;
		}
		//ReleaseLock();
	}
	AcquireLock();
	printf("IN: %d\n", in);
	ReleaseLock();
	return in;
}
开发者ID:pedrogrijo,项目名称:MC723,代码行数:35,代码来源:pi_par.c

示例6: main

int main()
{
	mv = CreateMV("mv1");
	mv2 = CreateMV("mv2");
	
	lck = CreateLock("lock1");
	lck2 = CreateLock("lock2");
	
	cv = CreateCV("cv1");

	for (loop =0; loop<500; loop++) 
	{
		AcquireLock(lck);
		SignalCV(lck,cv);

		AcquireLock(lck2);
		ret = GetMV(mv2);
		ReleaseLock(lck2);
		
		if (ret != 21)/*This will wait only if the other one isnt finished*/
			WaitCV(lck,cv);

		mvEdit = GetMV(mv);
		Print("Client 2: Monitor variable was read to be %d..",mvEdit,-1,-1);

		mvEdit+=7;
	
		
		ret=SetMV(mv,mvEdit);
		mvEdit = GetMV(lck);
	
		Print("Client 2: Monitor variable was set to be %d..",mvEdit,-1,-1);
		
		ReleaseLock(lck);	

		Print("Client 2: %d Iterations done..",loop,-1,-1);
	}
	
	AcquireLock(lck2);
	ret = SetMV(mv2,21);
	
	/*this monitor variable is set to 21 here to signify 
	*one of the processes is over and the other will not
	*wait for it to signal it
	*/
	ReleaseLock(lck2);
	
	AcquireLock(lck);
	SignalCV(lck,cv);
	ReleaseLock(lck);

}
开发者ID:achinksinghal,项目名称:CSCI_402,代码行数:52,代码来源:DistMVTest8_3.c

示例7: main

int main()
{
  const Lock& lock = AcquireLock();
  g = 1;
  g = 2;
  g = 3;
}
开发者ID:0day-ci,项目名称:gcc,代码行数:7,代码来源:Wunused-var-20.C

示例8: main

void main()
{
    lck = CreateLock("lock1");
    cv = CreateCV("cv1");
    Print("Client 2: Created Lock is %d and CV is %d\n", lck, cv, -1);

    AcquireLock("lock1");


    Print("Client 2: About to signal Client 1\n", -1, -1, -1);

    SignalCV("lock1","cv1");

    Print("Client 2: About to go on wait...\n", -1, -1, -1);


    WaitCV("lock1","cv1");
    for (i=0; i<10; i++)
        Print("\n",-1,-1,-1);

    Print("Client 2: Now out of wait...\n", -1, -1, -1);
    ReleaseLock("lock1");

    Exit(0);
}
开发者ID:achinksinghal,项目名称:CSCI_402,代码行数:25,代码来源:DistCVTest1_2.c

示例9: VerifyServices

static PromiseResult VerifyServices(EvalContext *ctx, Attributes a, Promise *pp)
{
    CfLock thislock;

    thislock = AcquireLock(ctx, pp->promiser, VUQNAME, CFSTARTTIME, a.transaction, pp, false);
    if (thislock.lock == NULL)
    {
        return PROMISE_RESULT_SKIPPED;
    }

    EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "promiser", pp->promiser, DATA_TYPE_STRING, "goal=state,source=promise");
    PromiseBanner(pp);

    PromiseResult result = PROMISE_RESULT_NOOP;
    if (strcmp(a.service.service_type, "windows") == 0)
    {
        result = PromiseResultUpdate(result, VerifyWindowsService(ctx, a, pp));
    }
    else
    {
        result = PromiseResultUpdate(result, DoVerifyServices(ctx, a, pp));
    }

    EvalContextVariableRemoveSpecial(ctx, SPECIAL_SCOPE_THIS, "promiser");
    YieldCurrentLock(thislock);

    return result;
}
开发者ID:dardevelin,项目名称:core-1,代码行数:28,代码来源:verify_services.c

示例10: thread3

void thread3()
{
    AcquireLock(a);
	Yield();
	Yield();
	Exit(0);
}
开发者ID:yoshE,项目名称:Operating_Systems,代码行数:7,代码来源:test4.c

示例11: main

int main()
{

	lock = CreateLock("lock");
	lock2 = CreateLock("lock2");

	cv1 = CreateCV("cv1");
	cv2=CreateCV("cv2");

	AcquireLock("lock");
	
	SignalCV("lock","cv1");
	
	Print("Client 2 is going to wait...",-1,-1,-1);
	
	WaitCV("lock","cv2");

	for (i=0; i<9; i++)
		Print("\n",-1,-1,-1);
	
	Print("Client 2 is now out of wait...",-1,-1,-1);

	ReleaseLock("lock");

	Exit(0);

}
开发者ID:achinksinghal,项目名称:CSCI_402,代码行数:27,代码来源:DistCVTest4_2.c

示例12: VerifyEnvironmentsPromise

void VerifyEnvironmentsPromise(EvalContext *ctx, Promise *pp)
{
    Attributes a = { {0} };
    CfLock thislock;
    Promise *pexp;

    a = GetEnvironmentsAttributes(ctx, pp);

    if (EnvironmentsSanityChecks(a, pp))
    {
        thislock = AcquireLock(ctx, "virtual", VUQNAME, CFSTARTTIME, a.transaction, pp, false);

        if (thislock.lock == NULL)
        {
            return;
        }

        PromiseBanner(pp);
        ScopeNewSpecialScalar(ctx, "this", "promiser", pp->promiser, DATA_TYPE_STRING);

        pexp = ExpandDeRefPromise(ctx, "this", pp);
        VerifyEnvironments(ctx, a, pp);
        PromiseDestroy(pexp);
    }

    YieldCurrentLock(thislock);
}
开发者ID:jooooooon,项目名称:core,代码行数:27,代码来源:verify_environments.c

示例13: ParallelFor

	void ParallelFor(const VectorType& items, const FuncType& func)
	{
		using SizeType = decltype(items.size());

		SizeType totalCount = items.size();

		auto lock = AcquireLock();

		SizeType offset = 0;

		for (int i = 0; i < m_ThreadCount; i++) {
			SizeType count = totalCount / static_cast<SizeType>(m_ThreadCount);
			if (static_cast<SizeType>(i) < totalCount % static_cast<SizeType>(m_ThreadCount))
				count++;

			EnqueueUnlocked(lock, [&items, func, offset, count, this]() {
				for (SizeType j = offset; j < offset + count; j++) {
					RunTaskFunction([&func, &items, j]() {
						func(items[j]);
					});
				}
			});

			offset += count;
		}

		ASSERT(offset == items.size());
	}
开发者ID:bebehei,项目名称:icinga2,代码行数:28,代码来源:workqueue.hpp

示例14: MonitorStartServer

void MonitorStartServer(const Policy *policy, const ReportContext *report_context)
{
    char timekey[CF_SMALLBUF];
    Averages averages;
    Promise *pp = NewPromise("monitor_cfengine", "the monitor daemon");
    Attributes dummyattr;
    CfLock thislock;

#ifdef __MINGW32__

    if (!NO_FORK)
    {
        CfOut(cf_verbose, "", "Windows does not support starting processes in the background - starting in foreground");
    }

#else /* !__MINGW32__ */

    if ((!NO_FORK) && (fork() != 0))
    {
        CfOut(cf_inform, "", "cf-monitord: starting\n");
        _exit(0);
    }

    if (!NO_FORK)
    {
        ActAsDaemon(0);
    }

#endif /* !__MINGW32__ */

    memset(&dummyattr, 0, sizeof(dummyattr));
    dummyattr.transaction.ifelapsed = 0;
    dummyattr.transaction.expireafter = 0;

    thislock = AcquireLock(pp->promiser, VUQNAME, CFSTARTTIME, dummyattr, pp, false);

    if (thislock.lock == NULL)
    {
        return;
    }

    WritePID("cf-monitord.pid");

    MonNetworkSnifferOpen();

    while (!IsPendingTermination())
    {
        GetQ(policy, report_context);
        snprintf(timekey, sizeof(timekey), "%s", GenTimeKey(time(NULL)));
        averages = EvalAvQ(timekey);
        LeapDetection();
        ArmClasses(averages, timekey);

        ZeroArrivals();

        MonNetworkSnifferSniff(ITER, CF_THIS);

        ITER++;
    }
}
开发者ID:cyphermaster,项目名称:core,代码行数:60,代码来源:env_monitor.c

示例15: CheckProcessMemory

	void CheckProcessMemory()
	{
		UINT_PTR i,j,flag,addr;
		DWORD len;
		CLIENT_ID id;
		OBJECT_ATTRIBUTES oa={0};
		HANDLE hProc;
		BYTE buffer[8];
		AcquireLock();
		id.UniqueThread=0;
		oa.uLength=sizeof(oa);
		for (i=0;i<count;i++)
		{
			id.UniqueProcess=(proc_record[i]&0xFFF)<<2;
			addr=proc_record[i]&~0xFFF;
			flag=0;
			if (NT_SUCCESS(NtOpenProcess(&hProc,PROCESS_VM_OPERATION|PROCESS_VM_READ,&oa,&id)))	
			{
				if (NT_SUCCESS(NtReadVirtualMemory(hProc,(PVOID)addr,buffer,8,&len)))
					if (memcmp(buffer,normal_routine,4)==0) flag=1;
				NtClose(hProc);
			}
			if (flag==0)
			{
				for (j=i;j<count;j++) proc_record[j]=proc_record[j+1];
				count--; i--;
			}
		}
		ReleaseLock();
	}
开发者ID:AndyScull,项目名称:interactive-text-hooker,代码行数:30,代码来源:SYS.cpp


注:本文中的AcquireLock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。