English 中文(简体)
WaitForSingle 目的不是锁定的,但允许其他胎面改变C++的价值。
原标题:WaitForSingleObject is not locking, Still allowing other threads to change value in C++

页: 1 WaitForSingleObject (fork [leftFork], /62/2/code> to lock aposition using multi threads, but it doesn tlock any

我制定了<代码>Handle fork[5],然后使用以下代码,但似乎没有锁定任何内容。

while(forks[rightFork] == 0 || forks[leftFork] == 0) Sleep(0);
WaitForSingleObject(fork[leftFork], INFINITE);
forks[leftFork]--;

WaitForSingleObject(fork[rightFork], INFINITE);
forks[rightFork]--; 

我曾尝试过<条码>。 WaitForMultipleObjects以及同样的结果。 当我创建中位数一时使用fork[i]= CreatMutex(NUL, FALSE,NUL);

我很想知道,这是否对每一条路面都有利,或者它们是否分享?

问题回答

首先,你没有表现出足够的准则,让我们能够以任何准确的确定性帮助你。 但是,在作出这一规定之后,我会尝试一条路!

你使用fork这个词向我表示,你正在视窗户背景阅读Windows 。 Windows threads没有什么不同。 相反,视窗中最有效的处理中转录物体不是exmut,事实上是临界部分

临界部分的接口非常简单,可以使用,基本上是一种功能和相应的释放功能。 如果你在单一过程中保持同步,而且你需要一个简单的锁点(而不是说气.),那么你就应当使用关键科而不是休克。

In fact, only yesterday here on Stack Overflow, I wrote a more detailed answer to a question which described the standard usage pattern for critical sections. That post has lots of links to the pertinent sections of MSDN documentation.

说到这一点后,似乎你们都在努力做到的是同步减少一系列的愤怒价值。 如果是这样的话,你就能够以24小时免费的方式这样做:>>>>InterlockIncrement或其朋友之一。

只有当你进行跨过程同步时,你才需要使用权差。 确实,由于关键部门表现得好得多(即速度更快),因此,只有在你协调整个进程时,你才能使用权差。 由于你正在更新一个简单阵列,而且由于显然没有看到独立党的继续,我只能得出结论,这实际上正在处理之中。

如果我错了,而且你确实正在做跨过程的工作,需要一刀切,那么我们就需要看到更多的法典。 例如,我看不出有人要求<代码>ReleaseMutex。 我不知道你是如何创造你们的财富的。

If this doesn t help, please edit your question to include more code, and also a high level overview of what you are trying to achieve.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签