Fork me on GitHub
#planck
<
2016-06-25
>
johanatan05:06:21

But I have bigger problems here now: can't do any JS/webkit/javascriptcore call from the bkg thread and I'm not sure how I could even send a message from the bkg thread to the main thread. Any ideas on that one?

mfikes05:06:55

JavaScriptCore is supposed to be thread-safe. So you should be able to call into it from any thread.

johanatan05:06:01

So, i can get a single JSValueMakeNumber to succeed, put it in an array and then try to create an object from that array with JSObjectMakeArray but it seg faults on the make array call

mfikes05:06:12

If it is doing that the first thing I’d do is uncomment the memory diagnostic sanitize address thing in the Makefile: https://github.com/mfikes/planck/blob/master/planck-c/Makefile#L7

johanatan05:06:39

Ok, trying that now

mfikes05:06:07

You may need to make clean and then make

johanatan05:06:18

yup, did that.

johanatan05:06:53

oh, found one stupid mistake. but after fixing that the previous (and serious one) still remains

johanatan05:06:30

looks like JSObjectMakeArray causes a "SEGV on unknown address 0x0000000000e8"

mfikes05:06:40

Sounds like fun. 😞

johanatan05:06:02

the ctx passed into it is exactly the ctx that was passed to us in the main thread

johanatan05:06:25

perhaps either a) that ctx isn't as permanent as we thought or b) ctx's can't be shared between threads like that .

mfikes05:06:26

Well, if it helps narrow it down, I’ve never had it SEGV on me by calling from different threads.

johanatan05:06:34

i'm leaning more towards the former

mfikes05:06:56

Good thing is that it is pretty well documented by Apple

johanatan05:06:04

but then again it's the same ctx that was just used for creating a number

johanatan05:06:12

well, early day tomorrow for me. I'll look at it again tomorrow afternoon/evening.

mfikes05:06:17

Well, so the API itself, JavaScriptCore, is a thread safe API.

You can call into various JSContext and evaluate code and create values and that sort of thing on different threads and everything will work fine.

mfikes05:06:30

Good video on it, that’s from the transcript: http://asciiwwdc.com/2013/sessions/615

mfikes05:06:29

Yeah, it is late here as well (East Coast US)

slipset06:06:19

@johanatan: a bit late to the party, but I’ve done this

slipset06:06:02

basically, when I want to listen to a socket, I pass a callback, in the form of a String: https://github.com/slipset/planck/blob/sockets/planck/PLKClojureScriptEngine.m#L713-L732

slipset06:06:51

and execute this callback in an iife like so:

johanatan18:06:28

@slipset: cool but are you doing that from a bkg thread?

johanatan18:06:16

Executing the callback isn't the problem right now-- it's the segfault lol

johanatan18:06:14

@mfikes: that's weird. I can't see anything else it could be. My JSContext looks legit and I was just previously able to create a JSNumber on it

johanatan18:06:00

And taking that number, packing it in an array and calling JSObjectMakeArray causes the segfault

johanatan18:06:14

Perhaps you can take a look if I push to my fork?

mfikes18:06:51

@johanatan: yeah, I may have some free time tonight to take a look

johanatan18:06:56

K, I'll do that in ~3-4 hours or so

slipset18:06:24

@johanatan: no, it's running in the same thread, but I needed a way to get noticed when someone wrote on the socket, hence the callback.