# Question on jl\_alloc\_array\_2d seg fault

**URL:** <https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 29, 2022, 8:10pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698 "2022-03-29T20:10:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdeoras](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdeoras/32/26326_2.png) [@sdeoras](https://discourse.julialang.org/u/sdeoras)\
**Post date:** [March 29, 2022, 8:10pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698/1 "2022-03-29T20:10:26Z")

</div>

Hi, I am interested in building a Go interface to Julia (for simple data passing and function evals) and having issues with `jl_alloc_array_2d`. In particular, repeated use of this function seems to intermittently lead to following seg fault:

```julia
signal (11): Segmentation fault
in expression starting at none:0
Allocations: 2722 (Pool: 2713; Big: 9); GC: 0

```

My use cases are very simple and in this particular example I am passing a 7x7 float64 data to Julia. The function mostly runs fine except that I get the above seg fault error once in a while.

I am wondering if there are recommendations on how to use memory allocation functions in Julia’s C interface? Thanks.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 29, 2022, 8:30pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698/2 "2022-03-29T20:30:52Z")

</div>

Can you share an example of what code you’re actually running when encountering this issue? I’m afraid the information you’ve provided is not enough to help diagnose it.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 29, 2022, 8:31pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698/3 "2022-03-29T20:31:16Z")

</div>

it’s almost certainly GC, both Go and Julia has a GC so it’s really annoying to make them play if you pass data back and forth

---

<div class="post-metadata">

**Author:** ![sdeoras](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdeoras/32/26326_2.png) [@sdeoras](https://discourse.julialang.org/u/sdeoras)\
**Post date:** [March 29, 2022, 9:05pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698/4 "2022-03-29T21:05:16Z")

</div>

Hi @Sukera it is a Go test where I am passing native Go data to a go-routine running Julia. It is in that go-routine where memory allocation of a 2D array of float64 data type happens. Currently that is the only operation I am testing, however, goal is to able to run just one go-routine with Julia embedded in it and have all other go-routines pass data to it.

In the past I ran into seg-fault issues where Julia was not safe to run in multiple go-routines with the requirements that all threads must be started by Julia runtime and not the foreign caller. It is for this reason why I am trying to isolate Julia related `cgo` calls to one go-routine.

[https://github.com/kubetrail/julia/blob/init-8/julia\_test.go#L717-L730](https://github.com/kubetrail/julia/blob/init-8/julia_test.go#L717-L730)

---

<div class="post-metadata">

**Author:** ![sdeoras](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdeoras/32/26326_2.png) [@sdeoras](https://discourse.julialang.org/u/sdeoras)\
**Post date:** [March 29, 2022, 9:07pm UTC](https://discourse.julialang.org/t/question-on-jl-alloc-array-2d-seg-fault/78698/5 "2022-03-29T21:07:35Z")

</div>

hi @jling, yes that is true and its been an issue in the past [Problems scaling jl\_alloc\_array\_2d C API](https://discourse.julialang.org/t/problems-scaling-jl-alloc-array-2d-c-api/63341)  
Considering my use cases are very simple I am hoping to arrive at a workflow where code is robust.
