Comments (7)
Hi @xafizoff can you give me a full source repro?
Also did you try with -threaded
?
Thanks.
from win32.
How to reproduce
> git clone https://github.com/xafizoff/haskell-win32-example.git
> cd haskell-win32-example
> cabal new-run haskell-win32-example-exe
Environment
> cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library
> ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3
from win32.
Also reproducible with Win32 v2.9.0.0. Sometimes you need to play with the cursor to freeze the program.
from win32.
That looks like it's because you're blocking the message pump. trackPopupMenuEx
is a blocking foreign call since it waits till the function returns. However in that time it's posting messages back the main Window expecting it to handle them, but the main loop is blocked so Windows marks the window as unresponsive.
(Graphics.Win32.tPM_RIGHTBUTTON .|. Graphics.Win32.tPM_NONOTIFY)
will tell it not to try to post messages to the Window but handle them in it's own loop, but external events can still make the Window unresponsive. i.e. focus changes.
That said I don't remember enough about these Window APIs to suggest a complete solution, my initial thought it the pump must be created on a different OS thread, or the menu. a C tutorial on how to use this should have the right approach.
from win32.
I don't know why it is blocking, probably due to Haskell RTS involvement, but similar C code works fine. So I ended up doing all GUI related stuff as a single foreign call. I just pushed it to github.
from win32.
This is almost certainly the fault of this unsafe foreign import:
https://github.com/haskell/win32/blob/master/Graphics/Win32/Menu.hsc#L426-L427
I surmise from this thread of issues that c_TrackPopupMenu
is a blocking function and thus should never be foreign imported unsafely. Unsafe foreign imports keep the RTS capability running Haskell code locked while the foreign code happens.
In multi-threaded runtime all capabilities must synchronise before GC can happen and those threads will block until synchronisation happens. Since the capability doing the unsafe foreign call can't synchronise this means all threads are blocked until the unsafe foreign call returns.
This is not the only dangerous unsafe foreign import, I found this issue after someone on IRC mentioned deadlocking when they used sleep
, which also does an unsafe foreign import and suffers the same problem.
The solution is to not import these unsafely. Or even better remove all unsafe foreign imports from the package except those that are 100%, definitely known to be safe (i.e. non-blocking and short running).
from win32.
Hello,
This is almost certainly the fault of this unsafe foreign import:
https://github.com/haskell/win32/blob/master/Graphics/Win32/Menu.hsc#L426-L427
hm I was sure I tried that, but most likely changed the wrong one. In any case I'll look into these again.
The solution is to not import these unsafely. Or even better remove all unsafe foreign imports from the package except those that are 100%, definitely known to be safe (i.e. non-blocking and short running).
Indeed, these UI bits were added as a mass import but clearly some slipped by.
from win32.
Related Issues (20)
- Win32-2.6.2.1, provided by GHC 8.10.6 and 8.10.7, is not on Hackage HOT 2
- `isMinTTY` no longer detects recent `mintty`s HOT 7
- Change maxLength to 16 in function getComputerName HOT 1
- If `--io-manager=native`, `withHandleToHANDLE` does not work for a 'console' `Handle` HOT 7
- `Setup.hs` seems inconsistent with the `build-type` option of the cabal file. HOT 1
- Support for `schannel.h` and `wincrypt.h` functions HOT 1
- Add constant `INVALID_SET_FILE_POINTER`
- Provide `GetTempFileNameW`
- Expose `FindData` struct HOT 5
- createFile without busy-wait HOT 6
- fails to start soon after starlink terminal power on HOT 1
- Change type synonym used in `loadLibrary{Ex}`'s return type from `HINSTANCE` to `HMODULE`
- Is it possible to use this package to control the Microsoft Excel application? HOT 2
- `System.Win32.MinTTY` doesn't detect newer versions of `mintty` (but perhaps that's OK) HOT 5
- Add setWindowPos and getConsoleWindow HOT 1
- Support filepath >= 1.5.0.0 and os-string HOT 1
- #221 Introduced unused-imports warnings which lead to failures in GHC HOT 7
- Make hackage revision for 2.13.3.0 HOT 3
- Can't retrieve registry value size HOT 2
- Please build and upload documentation to Hackage HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from win32.