runtime: make it possible to know the go initialization in shared libraries is finished without calling a go function #11768
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
Milestone
Please see golang-nuts › How to export C variables from Go shared libraries? for discussion.
I tried to write a Go shared library to make Apache or nginx modules.
What I would like to do is exporting a C struct variable, not a C function, from a Go shared library.
#1. What version of Go are you using (go version)?
1.5beta2
#2. What operating system and processor architecture are you using?
Ubuntu Linux trusty amd64
#3. What did you do?
Open a Go shared library written from a C main program. Please refer to the commit https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/tree/0972d57461b091aed35c9ed083af0edae0c885cc for source codes.
runtime_load.c
libgodll.go
Makefile
With these source codes above, I ran
make test_runtime
#4. What did you expect to see?
I expect to see
i=1
is printed at https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/blob/0972d57461b091aed35c9ed083af0edae0c885cc/runtime_load.c#L13#5. What did you see instead?
Actually
i=0
is printed at https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/blob/0972d57461b091aed35c9ed083af0edae0c885cc/runtime_load.c#L13Please see https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/tree/0972d57461b091aed35c9ed083af0edae0c885cc#load-a-shared-library-at-runtime-using-dlopen for the whole output.
When I added
usleep(1000 * 1000)
betweendlopen
and referencingi
,i=1
is printed at https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/blob/1951dfb411dcff8986687ca98f801505397fc6cf/runtime_load.c#L14Please see https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/tree/1951dfb411dcff8986687ca98f801505397fc6cf#load-a-shared-library-at-runtime-using-dlopen for the whole output.
Please refer to the commit https://github.com/hnakamur/export_c_variable_from_go_dll_experiment/tree/1951dfb411dcff8986687ca98f801505397fc6cf for source codes.
runtime_load.c
I would like to know when the Go initialization of shared libraries is finished without calling a Go function.
Ideally, I would like to set values of C variables at Go shared library compile time, instead of updating values of C variables with
init()
in a Go shared library.The text was updated successfully, but these errors were encountered: