mattwigway / OSRM.jl

MIT License
1 stars 0 forks source link

Confirm memory safety of new Json::object #2

Closed mattwigway closed 1 year ago

mattwigway commented 1 year ago

Before returning a route result from the C++ shim, we wrap it in a new object to force heap allocation. Does this do a deep copy, or is it possible there are some references to stack memory still in there?

mattwigway commented 1 year ago

Alternate, probably better solution: create a Julia callback that is called from C and just uses the values on the stack.

mattwigway commented 1 year ago

The Julia documentation says (emphasis mine):

Some C libraries execute their callbacks from a different thread, and since Julia isn't thread-safe you'll need to take some extra precautions. In particular, you'll need to set up a two-layered system: the C callback should only schedule (via Julia's event loop) the execution of your "real" callback.

It's likely we'll be running calls to OSRM in different Julia threads. Will that be an issue?

mattwigway commented 1 year ago

This thread seems to indicate that as long as the callback is in any Julia thread, it will be fine.