Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't terminate GLFW from ghci #45

Closed
lukexi opened this issue Feb 19, 2015 · 2 comments
Closed

Can't terminate GLFW from ghci #45

lukexi opened this issue Feb 19, 2015 · 2 comments

Comments

@lukexi
Copy link

lukexi commented Feb 19, 2015

Hi folks,

I'm trying to use GLFW from ghci, which is working excellently until it comes time to terminate the program. After calling GLFW.terminate, I'm left with a rogue GHC process that (from Sampling with Activity Monitor) seems deadlocked in some GHC threads.

I've narrowed it down to about as simple as it could be:

lukexi@LukeMBP:~$ ghci -fno-ghci-sandbox
GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ: import qualified Graphics.UI.GLFW as GLFW
λ: GLFW.init >> GLFW.createWindow 100 100 "test" Nothing Nothing >> GLFW.pollEvents >> GLFW.terminate
Loading package bindings-DSL-1.0.22 ... linking ... done.
Loading package bindings-GLFW-3.1 ... linking ... done.
Loading package GLFW-b-1.4.6 ... linking ... done.
λ: 

I'm then left with a generic "ghc" process that only goes away if I either Force-Quit it or kill ghci. Further calls to GLFW.init return False.

Here's the sample from Activity Monitor

Call graph:
    2742 Thread_1192120   DispatchQueue_1: com.apple.main-thread  (serial)
    + 2742 start  (in ghc) + 52  [0x100001c34]
    +   2742 main  (in ghc) + 115  [0x1000ead73]
    +     2742 hs_main  (in libHSrts_thr-ghc7.8.3.dylib) + 138  [0x106a7271a]
    +       2742 scheduleWaitThread  (in libHSrts_thr-ghc7.8.3.dylib) + 167  [0x106a76547]
    +         2742 schedule  (in libHSrts_thr-ghc7.8.3.dylib) + 502  [0x106a76756]
    +           2742 yieldCapability  (in libHSrts_thr-ghc7.8.3.dylib) + 354  [0x106a65f82]
    +             2742 waitCondition  (in libHSrts_thr-ghc7.8.3.dylib) + 6  [0x106a8ccf6]
    +               2742 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d0136]
    2742 Thread_1192121
    + 2742 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff9639641d]
    +   2742 _pthread_start  (in libsystem_pthread.dylib) + 176  [0x7fff963981e5]
    +     2742 _pthread_body  (in libsystem_pthread.dylib) + 131  [0x7fff96398268]
    +       2742 scheduleWorker  (in libHSrts_thr-ghc7.8.3.dylib) + 13  [0x106a770ed]
    +         2742 schedule  (in libHSrts_thr-ghc7.8.3.dylib) + 502  [0x106a76756]
    +           2742 yieldCapability  (in libHSrts_thr-ghc7.8.3.dylib) + 354  [0x106a65f82]
    +             2742 waitCondition  (in libHSrts_thr-ghc7.8.3.dylib) + 6  [0x106a8ccf6]
    +               2742 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d0136]
    2742 Thread_1192122
    + 2742 ???  (in <unknown binary>)  [0x109a258eb]
    +   2742 poll  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d15c2]
    2742 Thread_1192123
    + 2742 cbC6_info  (in libHSbase-4.7.0.1-ghc7.8.3.dylib) + 56  [0x10637c848]
    +   2742 kevent  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d121a]
    2742 Thread_1192125
    + 2742 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff9639641d]
    +   2742 _pthread_start  (in libsystem_pthread.dylib) + 176  [0x7fff963981e5]
    +     2742 _pthread_body  (in libsystem_pthread.dylib) + 131  [0x7fff96398268]
    +       2742 scheduleWorker  (in libHSrts_thr-ghc7.8.3.dylib) + 13  [0x106a770ed]
    +         2742 schedule  (in libHSrts_thr-ghc7.8.3.dylib) + 502  [0x106a76756]
    +           2742 yieldCapability  (in libHSrts_thr-ghc7.8.3.dylib) + 354  [0x106a65f82]
    +             2742 waitCondition  (in libHSrts_thr-ghc7.8.3.dylib) + 6  [0x106a8ccf6]
    +               2742 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d0136]
    2742 Thread_1192144   DispatchQueue_2: com.apple.libdispatch-manager  (serial)
    + 2742 _dispatch_mgr_thread  (in libdispatch.dylib) + 52  [0x7fff8b34aa6a]
    +   2742 kevent64  (in libsystem_kernel.dylib) + 10  [0x7fff8a9d1232]
    2742 Thread_1192197
    + 2742 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff9639641d]
    +   2742 _pthread_start  (in libsystem_pthread.dylib) + 176  [0x7fff963981e5]
    +     2742 _pthread_body  (in libsystem_pthread.dylib) + 131  [0x7fff96398268]
    +       2742 _NSEventThread  (in AppKit) + 137  [0x7fff89fee33b]
    +         2742 CFRunLoopRunSpecific  (in CoreFoundation) + 296  [0x7fff8ff54858]
    +           2742 __CFRunLoopRun  (in CoreFoundation) + 1371  [0x7fff8ff54ffb]
    +             2742 __CFRunLoopServiceMachPort  (in CoreFoundation) + 212  [0x7fff8ff55b34]
    +               2742 mach_msg  (in libsystem_kernel.dylib) + 55  [0x7fff8a9ca64f]
    +                 2742 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff8a9cb4de]
    2742 Thread_1192201: OGL Profiler
      2742 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff9639641d]
        2742 _pthread_start  (in libsystem_pthread.dylib) + 176  [0x7fff963981e5]
          2742 _pthread_body  (in libsystem_pthread.dylib) + 131  [0x7fff96398268]
            2742 glcDebugListener  (in OpenGL) + 336  [0x7fff940a89b5]
              2742 mach_msg  (in libsystem_kernel.dylib) + 55  [0x7fff8a9ca64f]
                2742 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff8a9cb4de]

(I'm not actually sure where the extra GHC threads are coming from yet...)

Is anyone doing this successfully?

@schell
Copy link
Collaborator

schell commented Feb 19, 2015

@lukexi the same thing happens to me with bindings-GLFW-3.0.4.0 and GLFW-b-1.4.6.

@Mokosha
Copy link
Collaborator

Mokosha commented Apr 9, 2018

This doesn't seem to be a GLFW-b problem. The following C-program exhibits the same behavior:

// test-glfw.c
#include <stdio.h>
#include "GLFW/glfw3.h"

int main() {
  glfwInit();
  GLFWwindow* win = glfwCreateWindow(100, 100, "test", NULL, NULL);
  glfwTerminate();

  while(1) {
    char s[256];
    scanf("%s", s);
    printf("echo: %s\n", s);
  }
}

I compiled this on OS X with GLFW pointing to master with the following command line:

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ gcc -o test-glfw test-glfw.c -I../install/glfw/src/include -lglfw3 -L../install/glfw/build/src  -framework AGL -framework Cocoa  -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo

If you think this is a GLFW-b problem, then please feel free to reopen with more details.

@Mokosha Mokosha closed this as completed Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants