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

allow safe goroutine usage #100

Open
TorchedSammy opened this issue Jul 29, 2023 · 6 comments
Open

allow safe goroutine usage #100

TorchedSammy opened this issue Jul 29, 2023 · 6 comments

Comments

@TorchedSammy
Copy link
Contributor

Currently when using golua in multiple goroutines it may cause a panic. I noticed this when I was using an event emitter which emitted events async via gorouties which results in a lot of random errors (and panics) shown here:

@arnodel
Copy link
Owner

arnodel commented Dec 4, 2023

Sorry for the very late response. Yeah, currently it is not safe to use the same golua.Runtime instance from multiple goroutines. It was not a design constraint, so I think it would be challenging to make it work in the most general case.
Depending on what you need it might be possible to make it work though, for example it could be possible to make a thread safe version of the Table data structure and that might provide enough thread safety (perhaps at a non-insignificant performance cost).

@TorchedSammy
Copy link
Contributor Author

At the very least, I want to run Lua event handlers asynchronously which I was able to do previously with gopher-lua. I also added a function in Lua that will run a callback in a goroutine.

I liked how gopher-lua added stuff that allowed parallel Lua code in the style of Go, with a channel type, select function, goroutine safety, etc.

@arnodel
Copy link
Owner

arnodel commented Dec 9, 2023

Ok, would you be able to give me an example of API you would like to use?

@TorchedSammy
Copy link
Contributor Author

What do you mean?

@arnodel
Copy link
Owner

arnodel commented Dec 11, 2023

If you wrote an example of how you would like to write some code that achieves that you want.

@TorchedSammy
Copy link
Contributor Author

go func() {
	rt.Call1(...)
}()

Being able to call functions and run Lua code in multiple goroutines at the same time.

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

No branches or pull requests

2 participants