8 ms·
Of course the language can be made to support it. Given the way Javascript is used, the question is whether supporting it will create a big mess. They have so
by Animats 9y ago
Of course the language can be made to support it. Given the way Javascript is used, the question is whether supporting it will create a big mess.
They have some good ideas. One is that variables can be marked as restricted to one thread. That should be the default. Other languages could benefit from that feature. Python, for example. If you want to get rid of the Global Interpreter Lock, knowing which variables can't be shared between threads is a big help.
Variables should be owned by a thread or owned by a lock. Rust went that way, and it works well. The proposal here is old C-style locking, where there are locks and variables, but the language doesn't know which locks are protecting which variables.
- pizlonator 9y agoI think it would be weird if objects were thread-restricted by default. Concurrency is most fun when it's easy for a thread to access an object it wants.
- richardwhiuk 9y agoYou say fun, but what you mean is twisted mess.
- pizlonator 9y agoWebKit uses threads. WebKit is not a twisted mess.
- coldtea 9y agoWebKit needs tons of extra effort to keep it from being a twisted mess precisely because it uses threads.
- pizlonator 9y agoCan you be very specific?
- coldtea 9y agoWhen told that multi-threaded access is hard and messy, "X program uses threads and it's not a mess" is not an argument -- for one because nobody said X program is a mess. Threads being messy is not a transitive property. Nobody doing threads ever said that they are not messy or that multi-thread access and locking et al are easy.
- pizlonator 9y agoI do threads and I just said that they are not messy.
- coldtea 9y agoWell, nobody sane then if I'm allowed the Scotsman! People also defend all kinds of dangerous constructs or practices blaming other programmers for not being good enough to use them even though statistically even the best programmers suffer from problems derived from them (e.g. buffer overflows, or in the case of threads race conditions, starvation, etc.). And since we're particularly talking about adding threads to Javascript, here's the opinion of the creator of Javascript itself on threads: You must be this tall to hack on threaded systems, and that means most programmers should run away crying. But they don’t. Instead, as with most other sharp tools, the temptation is to show how big one is by picking up the nearest ST code and jamming it into a MT embedding, or tempting race-condition fate otherwise. Occasionally the results are infamous, but too often, with only virtual fingers and limbs lost, no one learns. Threads violate abstractions six ways to Sunday. Mainly by creating race conditions, deadlock hazards, and pessimistic locking overhead. And still they don’t scale up to handle the megacore teraflop future. https://brendaneich.com/2007/02/threads-suck/ Also, are you the author of TFA? That sure speaks to your skills, but that doesn't mean standard definitions (e.g. on concurrency) or traditional consensus (e.g. on threads being messy) don't apply.
- olliej 9y agoAppealing to authority isn't a valid argument. Brendan and I have had many discussions about the nature of threading in JS. The reality is that to get high performance in JS on modern (and future afaict) is that JS will need to have some lower cost threading mechanism than that provided by workers. If you read the article you'll see that there isn't any way to mismatch lock/unlock. The other massive footgun is the for whatever reason people insist on creating standard libraries that are not thread safe (collections, apparently bigint in java?). JS is never going to have completely undefined behavior, but non-determinism already exists. Is concurrent code easier to screw up than single thread? yes. Is that cost enough to discount the possibility of ever having threads? I don't know. The article goes one way, you clearly go the other.
- LeoNatan25 9y agoAny well written software requires effort to properly design and maintain. What’s the argument here? “Don’t give them shotguns, they might shoot themselves”?
- PeCaN 9y agoDon't load the shotguns, turn off the safety, point it at their foot and tell them “please be careful”.
- pcwalton 9y agoI mean, you could say the same thing about assembly language programs. "Either static or dynamic typing is needed to prevent large programs from becoming a twisted mess" is a pretty uncontroversial statement today, despite the fact that there were some very high quality large assembly language programs written back in the DOS days. Besides, WebKit doesn't do fine-grained parallelism on the level of parallel styling or parallel layout. My colleague Manish came up to me after a long back-and-forth conversation with bz to figure out which objects were thread-safe and told me "the biggest lesson of Stylo is that adding parallelism to a previously large sequential C++ project is basically impossible". That's because large-scale projects invariably fail to properly document the precise synchronization invariants that each object must uphold in order to function properly. They settle for blanket statements like "the entire render tree is single threaded only" which, while conservatively a correct statement, essentially gives up on fine-grained tracking and makes it very hard to add parallelism later. By contrast, when you lift concurrency guarantees into the type system, the compiler essentially enforces that the documentation on thread safety is always up to date. This makes it way easier to start with sequential code and add parallelism (and/or concurrency) later as real-world profiling indicates fruitful optimization opportunities. I think you're way too casually dismissing the very real problems that unrestricted shared state has.
- pizlonator 9y agoWebKit does a lot of fine grained parallelism. I think you’re way too casually dismissing how awesome shared memory is.
- dbaupp 9y agoServo, which pcwalton works on, is largely motivated by the awesomeness of shared memory.
- pcwalton 9y agoWith all due respect, no, it doesn't do fine grained parallelism in the areas I described. Do I think it would be impossible to add parallel styling or layout to WebKit? No. Do I think it would be difficult? Absolutely, primarily because of the difficulty of finding all the concurrency hazards in existing objects and making them thread-safe. It would be easier with a type system that automatically checks for and highlights such problems. Such a system is precisely what I'm advocating. And I'm not saying not to use shared memory. I'm saying that shared memory should be controlled by some sort of static or dynamic type system that enforces proper locking or immutability as the case may be. Such a system is hardly a far-fetched idea, as we're successfully using one right now in the style system of nightly Firefox.
- jogjayr 9y agoIn fact I thought willy-nilly cross-thread access was the bane of multi-threaded programming. And also the main reason that immutability in languages such as Clojure is considered a desirable feature in support of concurrency.
- twic 9y agoImagine how much more fun it would be if threads sometimes got access to objects they didn't want!
- Sharlin 9y agoYeah, if by "fun" you mean "catastrophic"
- om2 9y agoI think the proposal was to thread-restrict variables, not objects. (Or more precisely, any variable is either restricted to a thread or guarded by a lock.) So it wouldn't actually stop you from accessing any object you want, as long as you can reach it from something in scope. But it also might not be a very useful safety guarantee.
- pizlonator 9y agoThread.restrict is about objects. It’s interesting to also have a function like that for properties and/or variables.
- pitaj 9y agoI share your concerns about the usefulness and implementation of this concurrency strategy. In my opinion, concurrency isn't necessary for JS. If web developers want high-performance, concurrent computing, they should push for adding concurrency to WASM. I doubt concurrency could hurt JS, but I just don't see any reason for it that concurrent WASM doesn't fulfill.
- stupidcar 9y agoAnd what about server developers using Node.js?
- pizlonator 9y agoRight! It can't be the all of the cool features are done in wasm, which doesn't even have a GC yet.
- vlunkr 9y agoWASM is farther along than concurrent JS though...
- pizlonator 9y agoThat's true. But most of the web is written in JS, not wasm.
- fermuch 9y agoIs there any limitation or reason for not implementing WASM on nodejs?
- pizlonator 9y agoIs there any limitation of reason for forcing people to rewrite their Node.js apps in something else just to get modern features?