Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sincos and thread safety #382

Answered by kgryte
ghalimi asked this question in Q&A
Discussion options

What does the comment WARNING: not thread safe mean on this line in relation to the sincos function? Since JavaScript is single-threaded (taking web workers aside), how could thread safety be an issue? Is this a legacy of an anterior C implementation?

You must be logged in to vote

This means that, if someone was porting to a language supporting multiple threads (e.g., C), then porting as is would not be thread safe. In JavaScript, we can elevate memory allocations out of functions as code does not need be reentrant. In C, we would not be able to do so.

Replies: 1 comment 3 replies

Comment options

This means that, if someone was porting to a language supporting multiple threads (e.g., C), then porting as is would not be thread safe. In JavaScript, we can elevate memory allocations out of functions as code does not need be reentrant. In C, we would not be able to do so.

You must be logged in to vote
3 replies
Comment options

If you fork a C program, then both programs have their own copy of the in-scope variables right? Wouldn't it still be thread safe then?

But in any case, I think the comments aren't needed. Someone porting to any other language should know what they're doing in their target language.

I believe the comments will cause more confusion there than benefit.

Comment options

Re: fork. Yes, that is correct.

The source comments are useful for us--that's why they are there--serving as a reminder as to how our internal native C and JS implementations should differ.

Comment options

New discovery today: JavaScript code which is not thread safe can affect whether V8 is able to perform certain optimizations. If a function is not thread safe, this can trigger de-optimizations. This was discovered on newer versions of V8 during profiling.

Answer selected by kgryte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Question General question. Math Issue or pull request specific to math functionality.

AltStyle によって変換されたページ (->オリジナル) /