本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例7: main
int main()
{
const Lock& lock = AcquireLock();
g = 1;
g = 2;
g = 3;
}
示例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);
}
示例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;
}
示例10: thread3
void thread3()
{
AcquireLock(a);
Yield();
Yield();
Exit(0);
}
示例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);
}
示例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);
}
示例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());
}
示例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++;
}
}
示例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();
}