c++ - glfwSleep() 如何导致段错误?

标签 c++ c segmentation-fault sleep glfw

在我的多线程应用程序中,我使用了一个 sleep() 函数(来自 GLFW 库的函数):

glfwSleep(..);

它显然导致我的应用程序出现段错误,正如我的调用堆栈所示:

#0 76CFC2BC WaitForSingleObjectEx() (C:\Windows\system32\kernel32.dll:??)
#1 00000016 ??() (??:??)
#2 0000006C ??() (??:??)
#3 00000000 ??() (??:??)

glfwSleep() 在线程内使用。那很危险吗?为什么我的程序会因此出现段错误?

编辑:

glfwSleep() 的参数小于 0.02(秒)时,它不会发生段错误!

编辑 2:

摘自GLFW的官方文档:

Writing threaded applications may be very awkward before you get used to it, but there are a few key rules that are fairly simple to follow:

  • ALWAYS assure exclusive access to data that is shared between threads!
  • Make sure that threads are synchronized properly!
  • NEVER busy wait!

我想我得到了答案..现在必须找到替代方案..

谢谢!

最佳答案

来自 the GLFW wiki :

GLFW doesn't work well with GHC threads, forkIO or threadDelay. So avoid them if you can.

关于c++ - glfwSleep() 如何导致段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/902687/

相关文章:

C++ 使用指向相同函数的指针作为模板参数是否总是会导致相同的实例化?

c++ - 在 gdb 中打印整个链表?

c函数链接可能吗?

c - C 中的 “Initializer element is not constant”

segmentation-fault - Fortran 奇怪的赋值,是 4294967295 == .true.?

c++ - 了解析构函数

c++ 到 vb.net,情侣对话问题

objdump 和 gdb 的组合

c - unix 守护进程因未知原因停止且没有 coredump

c - 我应该如何修复这个有趣的 getdelim/getline (动态内存分配)错误?