Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple embedded sessions #512

Open
actondev opened this issue May 8, 2020 · 4 comments
Open

Multiple embedded sessions #512

actondev opened this issue May 8, 2020 · 4 comments

Comments

@actondev
Copy link

actondev commented May 8, 2020

I'm wishing to embed chez in a c++ application.
Is it possible to initiate multiple independent scheme sessions?

I see in https://github.com/cisco/ChezScheme/blob/b7f161b/c/scheme.c#L38 that the heap_state is static. So.. I guess not possible? Would there be any plans to support this?

@gwatt
Copy link
Contributor

gwatt commented May 8, 2020

One thing you can do right now is spawn different environments and execute your code in those environments with eval. It's not quite the same as completely different sessions since you can change global and thread parameters that are shared across all environments, but it's close and you can hide the effects of modifying parameters with parameterize.

You can either construct fresh environments with environment or copy the interaction-environment with copy-environment

@actondev
Copy link
Author

thanks @gwatt ! Wasn't aware of the environments thing, will look into that at some point.
For now my issue can be solved, but however I think the modularization of the code (eliminating static) should be done at some point.

More specifically, my issue was when making a dynamic C++ library using scheme, to be loaded by a host application. The host application could instantiate multiple instances of this library. (more specifically it's about doing a VST plugin, being loaded by a VST host)

The issue that I stumbled upon was that scheme was already initiated when a 2nd instance of my plugin is loaded, thus crashing.

Thanks again.

@gwatt
Copy link
Contributor

gwatt commented May 19, 2020

If it's acceptable to have plugins sharing the same scheme runtime but with their own scheme environments, you can check that the scheme system is already initialized and then skip the rest as appropriate. Sscheme_init checks the current state and then calls a given procedure if the initialization process is underway or complete. If the given procedure is NULL, the system aborts.

int initialized = 0;

void set_initialized(void) {
    initialized = 1;
}

// on plugin initialization
Sscheme_init(&set_initialized);
if (!initialized) {
    Sregister_bootfile(...);
    Sbuild_heap(...);
}

@actondev
Copy link
Author

Yeah that's more or less what I thought of doing.
One note: I think the init function should be moved inside the if block.

For reference, that's the error I was getting
error (Sscheme_init): call Sscheme_deinit first to terminate

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

No branches or pull requests

3 participants