Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Multi-thread code samples request #78

Open
commonsuppliz opened this issue Apr 27, 2017 · 6 comments
Open

Multi-thread code samples request #78

commonsuppliz opened this issue Apr 27, 2017 · 6 comments

Comments

@commonsuppliz
Copy link

I need to access chakraCore in different thread out of owner context thread (ex. background).
Current existing sample in C# is just in one thread. I need sample code to work in multi-thread chakraCore.

@liminzhu
Copy link
Member

liminzhu commented Apr 27, 2017

Handling multiple threads would be an interesting topic. It's important to understand that a runtime can only live on one thread at a time (see rental-threading). So in order to switch a runtime from thread A to thread B, you need to give up the runtime on thread A,

// on thread A
JsSetCurrentContext(nullptr);

// on thread B
JsSetCurrentContext(context1);

@commonsuppliz
Copy link
Author

Do You means generated JS Objects wll adhere to one thread (Context), and can not pass across the thread?

@liminzhu
Copy link
Member

No. All your JS objects are adhered to the context they are created on, and you can move context between threads.

@liminzhu
Copy link
Member

https://github.com/Microsoft/ChakraCore/wiki/JavaScript-Runtime-%28JSRT%29-Overview#concepts should give you a good idea about what runtime and context are.

@commonsuppliz
Copy link
Author

I understand "and you can move context between threads.", and I beg to provide C# code to demonstrate in C# to rental thread context switching.

@liminzhu
Copy link
Member

liminzhu commented May 1, 2017

Is there a particular scenario that you're after? I believe the general idea regardless of language is in #78 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants