https://github.com/jagobagascon/go-deadlock-example
https://github.com/jagobagascon/go-deadlock-example
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jagobagascon/go-deadlock-example
- Owner: jagobagascon
- Created: 2022-09-12T10:41:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-19T09:29:22.000Z (over 1 year ago)
- Last Synced: 2025-02-08T10:44:52.801Z (4 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is an example project to reproduce this issue: https://github.com/golang/go/issues/55015
The project contains two folders.
Both of them contain the exact same code: a (not so) small example of an application scanning for BLE devices using the WinRT BLE APIs.Both applications start a BLE scan operation, and wait indefinitely. Windows will execute the callback everytime a device is found.
The only difference is that one of them uses `malloc` to allocate memory into the heap, and thus, uses CGO. And the other one uses `HeapAlloc` via syscall, so it does not need CGO.
> [!NOTE]
> `example-malloc` is pointing to the latest release of https://github.com/saltosystems/winrt-go, which uses `malloc` for allocation of delegates.
> `example-heapalloc` is pointing to this PR https://github.com/saltosystems/winrt-go/pull/60, which replaces it for the `HeapAlloc` function.## Expected behaviour
Both applications should list the address of the devices they find.## What really happens
- `example-malloc` is working as expected: listing the address of the bluetooth devices it scans.
- `example-heapalloc` is failing with the following error:
```
fatal error: all goroutines are asleep - deadlock!goroutine 1 [chan receive]:
main.runExample()
C:/projects/go-deadlock-example/example-heapalloc/main.go:79 +0x3ee
main.main()
C:/projects/go-deadlock-example/example-heapalloc/main.go:14 +0x19
exit status 2
```If you add a goroutine to `example-heapalloc`, then it works as expected. Even if the goroutine does nothing but wait:
```go
go func() {
<-time.After(5 * time.Second)
}()
```This issue seems related to https://github.com/golang/go/issues/6751