- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将应用程序从 VC6 升级到 VS2010(旧版代码)。该应用程序在 VC6 中正常运行,但在将项目转换为 VS2010 后,我遇到了一些问题。退出应用程序时,程序会在尝试锁定进入临界区时中断。锁定计数通常从 -1(未锁定)到 -2(锁定)交替变化,但就在程序崩溃之前,锁定计数为 0。
g_RenderTargetCriticalSection.Lock();// Breaks here
if (g_RenderTargets.Lookup(this, pRenderTarget))
{
ASSERT_VALID(pRenderTarget);
g_RenderTargets.RemoveKey(this);
delete pRenderTarget;
}
g_RenderTargetCriticalSection.Unlock();
这是 CCriticalSection::Lock()
函数,其中 ::EnterCriticalSection(&m_sect);
失败。我发现很奇怪,在失败时,锁定计数从 0 变为 -4??
_AFXMT_INLINE BOOL (::CCriticalSection::Lock())
{
::EnterCriticalSection(&m_sect);
return TRUE;
}
如果有人遇到过类似的事情,将不胜感激。提前致谢。
最佳答案
注释表明这是一个文件范围对象析构函数顺序问题。有多种方法可以解决这个问题。由于我还没有看到其余代码,因此很难提供具体建议,但一个想法是将 CS 更改为存在于 shared_ptr
中,并让您的 CWnd 保留一个拷贝,这样它就不会不要过早销毁。例如:
std::shared_ptr<CCriticalSection> g_renderTargetCriticalSection(new CCriticalSection());
然后在你的窗口类中:
class CMyWindow : public CWnd
{
private:
std::shared_ptr<CCriticalSection> m_renderTargetCriticalSection;
public:
CMyWindow()
: m_renderTargetCriticalSection(g_renderTargetCriticalSection)
{
// ...
}
~CMyWindow()
{
// guaranteed to still be valid since our shared_ptr is keeping it alive
CSingleLock lock(m_renderTargetCriticalSection.get(), TRUE);
// ...
}
// ...
};
关于c++ - 应用程序在 CCriticalSection::Lock 上中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23410470/
我想知道锁是如何在 Java 中实现的。在一些教程中,我发现它们应该使用 wait() 和 notify()/notifyAll() 以及一些 boolean 标志来实现(它可能比那复杂得多,但基本上
我正在开发一个多线程服务器,用于存储和读取来自数据库的信息。数据库是用 RocksDB 实现的。 我遇到的问题是,当我一次从多个线程访问数据库时,我得到了那个错误。 通常是说db在usign后没有被删
例如,这里有一些 linux 中的代码: void set_leds(int val) { int fd = open ("/dev/console", O_WRONLY); // argumen
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
考虑以下代码。为了防止IndexOutOfBoundsException打电话时 listIterator ,我们使用读取器锁来检索基于索引的 iteartor,并在对 stockCodes 进行写操
这个问题在这里已经有了答案: Java locking structure best pattern (2 个答案) 关闭 6 年前。 有什么区别: private Lock lock = new
是否可以在网页加载时检查 Scroll Lock、Num Lock 和 Caps Lock 的状态?我找到了使用 JavaScript 在按键后进行检查的方法,但这不是我要问的。 最佳答案 2019
是否可以在网页加载时检查 Scroll Lock、Num Lock 和 Caps Lock 的状态?我找到了使用 JavaScript 在按键后进行检查的方法,但这不是我要问的。 最佳答案 2019
在Ubuntu中安装某些东西时出现错误。我尝试了一些命令来杀死正在运行的进程,但仍然遇到相同的错误。 最佳答案 根据文章How to Fix “Waiting for cache lock: Coul
我们有一个gradle构建,它可以动态创建GradleBuild类型的多个任务,以与不同的客户端库版本一起运行以测试其兼容性。在Gradle4上可以正常工作,但是在移至Gradle5后,执行第一项任务
我在尝试运行在 vertica 数据库表上运行查询的客户端应用程序时反复遇到此错误。 有人可以帮助解决这个问题吗? 最佳答案 我想知道您的客户端应用程序向 Vertica 发送了哪种“查询”(以 RE
我有一个创建锁的方法。 ReadWriteLock lock = new ReentrantReadWriteLock(); 然后我使用 Lock Interface 将该对象传递到一个方法中。 m
正如问题所问,我知道这是可能的on Linux ,但我找不到任何适用于 Windows 的最新信息。有可能吗? 最佳答案 您可以使用 ctypes 加载 user32.dll 然后调用 GetKeyS
这是同一个问题 Change keyboard locks in Python或者 How to change caps lock status without key press . 但还是有区别的
与 this question 相同,不知道为什么Java团队没有在Lock中添加一些默认方法界面,类似这样: public default void withLock(Runnable r) {
我有一个带有package-lock.json文件的项目。 现在,我想基于yarn.lock文件或项目的现有package-lock.json生成node_modules文件。 我怎样才能做到这一点?
我正在查看 pthreadtypes.h 文件中的 pthread_mutex_t 结构。 “__lock”代表什么?它就像分配给互斥锁的锁号吗? typedef union { struct _
我正在研究避免死锁的措施,其中一种可能的方法是通过强制线程放弃它在访问另一个锁但无法访问该锁时已经持有的锁来打破循环等待。 以最简单的银行账户转账为例: class Account { priva
我被要求支持一些遗留代码,我看到了一些让我摸不着头脑的事情。在某些代码段中,我看到类实例使用 CMutex 实例来同步方法执行。例如 class CClassA : public CObject {
当我们调用 lock.lock() 或尝试进入一个 synchronized block 时,如果其他线程已经获取了该锁,我们的线程就会阻塞。现在我的问题是,当我们查看 lock.lock() 的实现
我是一名优秀的程序员,十分优秀!