Comments (8)
Good point.
from node-fibers.
Would definitely make clear that you can develop threadlike but does not use threads, while in many discussions people get the details of node-fibers completly wrong, they think you've implemented threads and they would loose all the asynchronous nodejs efficiency,
from node-fibers.
I also was wondering about https://github.com/laverdet/node-fibers/blob/master/src/coroutine.cc#L27 which states:
// Assume that v8 registered their TLS keys within the past 5 keys.. if not there's trouble.
What (and why) exactly does it depend on V8 TLS keys for?
So far I could only find that V8 Isolates uses TLS (through the V8 Thread::LocalStorageKey Thread::CreateThreadLocalKey() API in platform-win32.cc)
from node-fibers.
v8 uses TLS to determine which execution stack is currently running, and if v8 has been initialized in this context. Since v8 is creating machine code on the fly it needs to some extra information about the stack it's on. In most cases threads and stacks are 1:1 but fibers violate this by switching out the stack without v8 knowing it. To get around this, fibers also swaps out the last 5 TLS keys registered so that v8 thinks each new fiber is a new thread. Note that when using CORO_PTHREADS this step is skipped.
from node-fibers.
If I understand correctly then fibers are implemented through V8 isolates? (and the Locker API is used to 'switch' between isolates and have V8 initialise if needed?)
Is there any place outside isolates that make use of TLS in V8?
I have been looking through the V8 code and so far it seems that only Isolates are actually using TLS.
The Isolates API exposes (2 of the 3) TLS keys used through Isolate::isolate_key() and Isolate::thread_id_key(). Unfortunately I can't find an implementation for Isolate::per_isolate_thread_data_key() although it is definded in the API.
Would it help to make node-fibers use the V8 TLS api to switch the 'right' TLS keys (instead of using the pthread API directly)? That would also prevent setting any TLS to NULL for keys that are not used by V8 (so far I could only see V8 using 3 TLS keys in the Isolates implementation, while coroutine::transfer resets possibly 5 TLS keys)
from node-fibers.
hmm, apparently the Isolate API I looked at was internal to V8, sorry for that
from node-fibers.
Yeah those are internal to v8. You can access them under the symbol v8::internal::* if v8 is compiled as a dynamic library, but it is an archive by default in node so no go. Over-swapping TLS isn't really a problem though. TLS keys are mostly just pointers returned by functions like String::c_str(). In an earlier version of node-fibers, all TLS keys were swapped:
https://github.com/laverdet/node-fibers/blob/02c50facd989986932ff93445f9c20045532d8bb/src/coroutine.cc
v8 switched from using pthread_self() for thread identity to a TLS key, though, which made everything a lot easier for me.
from node-fibers.
I'm going to go ahead and close this. node-fibers is a highly technical project and if you're having problems with what it is you will probably discover something like asyncblock first anyway.
from node-fibers.
Related Issues (20)
- Binary is not included when installing fibers on Ubuntu 18.04 with Node 15 HOT 1
- ES6 Module support
- NPM install error for fibers HOT 1
- npm install fibers with error(node v12.15.0) HOT 8
- A Big Thank You HOT 3
- Debian9: Assertion `thread_id_key != 0x7777' failed HOT 2
- C++ compile errors trying to install fibers @3.1.1 HOT 4
- node process blocks if you use fiber in proces.once('exit', ...) callback
- not support python3?
- what to do it does not work on node 16 but I really need this package for the code to work HOT 1
- Latest version 5.0.2 is not tagged. HOT 4
- New NPM version released HOT 1
- latest version 5.0.2 won't install HOT 2
- Maintenance
- Whether the node version v16.x.x is supported HOT 1
- Fails to build on debian testing (required for rocket.chat 😕 ) HOT 4
- node: ../src/coroutine.cc:134: void* find_thread_id_key(void*): Assertion `thread_id_key != 0x7777' failed. Aborted (core dumped)
- When i start my back-end app then saw this error recently
- Node 20.6.1 support HOT 1
- Cannot find module win32-x64-108\fibers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-fibers.