Use IUP to write window procedures, not into the thread pool module, you can normally compile and run. If you import the thread pool module, you can compile, but can not run successfully.
tips:Illegal storage access. SIGSEGV: (to read from nil Attempt?)
What is the reason?
import iup, os, threadpool
proc startServer(arg:PIhandle):cint{.cdecl.}=
var a= execShellCmd("cx.exe")
message("title","start!")
if open(nil,nil) == IUP_ERROR:
message("title","error!")
else:
var label1 = label("find")
var bt_start = button("start", nil)
var bt_stop = button("stop", nil)
setattribute(bt_start,"SIZE","50×")
setattribute(bt_stop,"SIZE","50×")
var hbox1 = hbox(bt_start,bt_stop,"EXPAND=YES, ALIGNMENT=ACENTER")
var vbox1 = vbox(label1,hbox1,"EXPAND=YES, ALIGNMENT=ACENTER")
setattribute(vbox1, "GAP", "5")
setattribute(vbox1, "MARGIN", "10×10")
var dlg = dialog(vbox1)
setattribute(dlg, "TITLE", "server")
setattribute(dlg, "SIZE", "200×100")
showxy(dlg,IUP_CENTER,IUP_CENTER)
setCallback(bt_start,"ACTION",(Icallback)startServer)
mainLoop()
close()
I got the same problem: SIGSEGV: (to read from nil Attempt), using IUP 3.17 on WIN64/Win7, MINGW64, NIM 0.13. However, the program worked as expected when I added a prompt at the error-bearing line No 16, which comes as a surprise.
import iup, os, threadpool
proc startServer(arg:PIhandle):cint{.cdecl.}=
var a= execShellCmd("cx.exe")
message("title","start!")
if open(nil,nil) == IUP_ERROR:
message("title","error!")
else:
var label1 = label("find")
var bt_start = button("start", nil)
var bt_stop = button("stop", nil)
setattribute(bt_start,"SIZE","50×")
setattribute(bt_stop,"SIZE","50×")
var hbox1 = hbox(bt_start,bt_stop,"EXPAND=YES, ALIGNMENT=ACENTER")
echo "until now..." #program stopped here, but the echo stmt "repairs" it...
var vbox1 = vbox(label1,hbox1,"EXPAND=YES, ALIGNMENT=ACENTER")
setattribute(vbox1, "GAP", "5")
setattribute(vbox1, "MARGIN", "10×10")
var dlg = dialog(vbox1)
setattribute(dlg, "TITLE", "server")
setattribute(dlg, "SIZE", "200×100")
showxy(dlg,IUP_CENTER,IUP_CENTER)
setCallback(bt_start,"ACTION",(Icallback)startServer)
mainLoop()
close()
#program stopped here, but the echo stmt "repairs" it...
I had a similar observation some weeks ago with GTK3 -- it occurred only with gcc 5.3 with options -O3 and -march=native. An echo or declaring a variable volatile made it working again, so I think it was a C compiler bug. Maybe you can try without O3 or maybe with clang. And, as your example is really small maybe looking at the C code may help.