Hi there, I am encountering a cgo problem (unsure, most likely) when migrating an old C library to Go.
A cgo call calls a component of the C library, which internally creates an OS thread and then calls libpango (pango_cairo_font_map_get_default() call). The original pure C code is able to go through the pango call: printf("before call"); font_map = pango_cairo_font_map_get_default(); printf("after call"); Outputs: before call after call After involving Go, the code stuck at the Pango call after its first calling, and prints the following warning and critical message from GLib: before call (process:1): GLib-GObject-WARNING **: cannot register existing type 'PangoFontMap' (process:1): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed (process:1): GLib-GObject-CRITICAL **: g_type_register_static: assertion 'parent_type > 0' failed (process:1): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed (process:1): GLib-GObject-CRITICAL **: g_type_register_static: assertion 'parent_type > 0' failed (process:1): GLib-GObject-WARNING **: cannot register existing type 'PangoCairoFontMap' Call chain: round1: go code --> goroutine --> cgo --> c --> dlopen --> back to go --> hold a pointer points to C memory in Go--> goroutine --> cgo --> pass the pointer to C --> pthread_create --> pango_font_map_get_default() --> success! round2: same call chain --> fail! message in above My understanding of pango_font_map_get_default() is the call will always a success because of thread safe (after v1.36, internal font-map managed by pango is per-thread), and can be called multiple times, i.e. the call must success. Thus, a suspicion leads to somehow cgo or Go memory allocator influence the C side. My questions are: 1. Is my suspicion reasonable and correct? 2. Why an error when involving cgo? 3. Are memories in a non-Go thread completely isolated to Go memory per-non-Go thread? 4. Are C memories allocated in a cgo call always stands in the same sharing heap even threading? 5. Any other theories and how cloud possibly solve the problem? 6. If I am asking a wrong question, could you shoot any ideas of solving the issue described above? Thank you very much in advance. Best, changkun -- 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. For more options, visit https://groups.google.com/d/optout.