當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。