Re: [go-nuts] Closing write side of os.Pipe caused different behaviors

2024-11-10 Thread huan xiong
Hi Kurtis, Thanks for your detailed explanation. It all makes sense to me (I figured out the race condition issue after I posted the question. As it was the first time I posted to the group, I couldn't reply to my own question until the moderator approved it). For future me and other beginner

Re: [go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread Jason E. Aten
I never needed to do CreateThread(), so I doubt it is needed? I would add printf debugging statements to see when things are happening. Since Windows processes do not normally have the concept of stdout however, you do have to write them to a file instead of "the console", which is not there by d

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread rudeus greyrat
Thanks, it works now. I was missing the CreateThread in DLL Main ``` case DLL_PROCESS_ATTACH: // Initialize once for each new process. // Return FALSE to fail DLL load. { MyThreadParams* lpThrdParam = (MyThreadParams*)malloc(sizeof(MyThreadParams )); lpThrdParam->hinstDLL = _hinstDLL; lpTh

Re: [go-nuts] Re: no direct write to a complex types components?

2024-11-10 Thread 'simon place' via golang-nuts
OK, i have it, apologies.. i was benching the complex path with an extra dereference and with such a tight loop it makes so much more difference than i thought was possible. now all makes sense. thanks. On Sunday 10 November 2024 at 19:25:39 UTC Axel Wagner wrote: > On Mon, 11 Nov 2024 at 03

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread Jason E. Aten
I would suggest divide and conquer next. This is a classic approach to debuggging. First get something working in C, solely on Windows. Can you build a pure C host and pure C DLL that loads and shows your window? I note that I never had much luck cross-compiling to windows, so I would recomme

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread rudeus greyrat
Update So there is some lock put if there is an export in the go file which is causing the problem. To fix I was inspired by this guy https://gist.github.com/NaniteFactory/7a82b68e822b7d2de44037d6e7511734#file-dllmain-go dllmain.go: ``` package main /* #include "dllmain.h" */ import "C" ```

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread rudeus greyrat
Thanks for your response. It seems logic to do what you say (aka lets make DllMain in C if Go does not let us control it) So I did a main.c: ``` #include extern void RunMe(); BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call)

Re: [go-nuts] Re: no direct write to a complex types components?

2024-11-10 Thread 'Axel Wagner' via golang-nuts
On Mon, 11 Nov 2024 at 03:24, 'simon place' via golang-nuts < golang-nuts@googlegroups.com> wrote: > yes, see the bench and code in the OP. > I don't see any benchmarking code in this thread. >From the godbolt output , it looks to me as if the compiler generate

Re: [go-nuts] Re: no direct write to a complex types components?

2024-11-10 Thread 'simon place' via golang-nuts
On Sunday 10 November 2024 at 01:26:51 UTC Dan Kortschak wrote: On Sat, 2024-11-09 at 17:01 -0800, 'simon place' via golang-nuts wrote: > > > That's because Complex numbers are immutable - just like strings, > > and regular numbers for that matter. > > > > Hence to replace one component of

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread Jason E. Aten
I'll add that the one way I've found to address the "Go runtime cannot shut itself down" problem is to compile to wasm. WebAssembly hosts like the browser -- and running the wasm on a background web worker -- provide very nice ways of killing a web worker thread. I believe (but have not tried it

[go-nuts] Re: Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread Jason E. Aten
Use CGO in your .go file, and then there, or in an adjacent C file, actually do write a DllMain function; https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain When fdwReason == DLL_PROCESS_ATTACH, then you know this is the first load of the DLL into this process. I think your subject lin

[go-nuts] Equivalent of DLL_PROCESS_ATTACH in Go

2024-11-10 Thread rudeus greyrat
I am trying to write DLL in go. I want it to execute some stuff when the DLL is attached to a process. I thought init() will be the equivalent of onattach but It seems I am wrong. I created this as a proof of concept: ``` package main import "C" import ( "syscall" "golang.org/x/sys/windows"