Hi, 
I am planning to replace C++ threadpool class with goroutines. I see 
several go implementations for threadpool. 

few are 
https://github.com/panjf2000/ants/

I am having issue, when i need to call back and forth . preferably, I need 
to keep C++ function has main. C++ function calls SubmitTask. Go library 
should call run with the ID i passed to SubmitTask.

Please let me know reference or links which could help me. 



// main.go

import "C"
func SubmitTaskHandler(workitem interface{}) {
    itemid := workitem.(int32)
    fmt.Println(itemid)
    tmp := C.int(itemid)
    C.run(tmp)
}
//export SubmitTask
func SubmitTask( x int32) {
    fmt.Println("GO called from C ")
    _ = pool.Invoke(int32(x))
}

func main() {
    defer ants.Release()
    var runTimes int32 = 1000
        for i := int32(0); i < runTimes; i++ {
            go SubmitTask(i)
        }

    fmt.Scanln()
        fmt.Println("done")
        fmt.Printf("running goroutines: %d\n", ants.Running())
        fmt.Printf("finish all tasks.\n")

}



test.c file:
#include "_cgo_export.h"
void submittask(int i)
{
    SubmitTask(i);
}


Regards,

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f1119a0a-65a5-4ac6-b08c-deb07446d004%40googlegroups.com.

Reply via email to