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

Race condition in reader #490

Open
hemml opened this issue Oct 21, 2023 · 5 comments
Open

Race condition in reader #490

hemml opened this issue Oct 21, 2023 · 5 comments

Comments

@hemml
Copy link
Contributor

hemml commented Oct 21, 2023

When executing read or read-from-string in multitasking environment, a race condition exists with jscl::labelled-objects, which is a global variable.
The following code is thread safe:

(let ((jscl::*labelled-objects* nil))   ;; workaround for JSCL reader race condition
  (jscl::ls-read-from-string s))

I'm using jscl::ls-read-from-string when compiling lisp code on the host (with SBCL, for example), because quasiquotation symbols are not standardized yet and I have to write-to-string my code and read it with jscl::ls-read-from-string to get a proper representation for jscl::compile-toplevel.

@hemml
Copy link
Contributor Author

hemml commented Oct 25, 2023

The same situation with *macroexpander-cache* hash table, concurrent modifications of the table causes error in SBCL.

@davazp
Copy link
Member

davazp commented Oct 26, 2023

I think requiring a single thread in host is okay in this context. Especially because JS is also single threaded.

It's true that it would make easier to exploit async programming in JS but it would add lot of complexity.

@davazp
Copy link
Member

davazp commented Oct 26, 2023

What is your use case for multithreading with compiling JSCL?

@hemml
Copy link
Contributor Author

hemml commented Oct 27, 2023

I'm compiling CL code into JS and sending it to the browser to execute. The browser just evaluating everything it got from the websocket via eval(). This allows me to avoid any communication protocols. If I want to change something in the browsers state, I'm just sending a code which perform needed changes. Also, I can define functions in the browser (again, just by sending a (defun .... ...) compiled into JS) and use them for any internal UI logic. I'm developing the OMG library which simplifies all that tasks.

I can send CL code itself and execute it via eval in JSCL on browser-side, but JSCL compilation in browser is terrible slow. I believe that because JSCL reader is slow. So, I'm compiling the code on the backend. And stomping on race conditions sometimes.

@hemml
Copy link
Contributor Author

hemml commented Dec 30, 2023

I have released a first web application using this technique (if interesting): https://github.com/hemml/TomoV
This is a complete in-browser Doppler tomography reconstruction application (for astronomical data), uses OMGlib, web workers, Storage API and, of course, JSCL :)

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