r/learnjavascript • • May 01 '20

Async vs. Sync

Post image
413 Upvotes

81 comments sorted by

View all comments

Show parent comments

2

u/HeinousTugboat May 03 '20

So, pthreads aren't multithreaded? Node doesn't use V8 for threading, it uses libuv which has its own threading API that Node interfaces with. I, admittedly, have no idea what you're referring to when you say that "at most you get the ability to lob logic whenever you use up too much memory".

If pthreads aren't multithreaded, then what do you mean when you say multithreading in a language? I can write a short node program that will run on four cores on my processor. Full stop. That, to most people I imagine, is multithreading. So what's missing from that definition to you?

Anyway, all of this is also ignoring the fact that you can fork your heart out in node. Does this mean it's still not multithreaded? Because at that point is there any language that's multithreaded on a POSIX system?

0

u/[deleted] May 03 '20

Pthreads are not JavaScript. And... That's why JavaScript isn't multithreaded....hey...

2

u/HeinousTugboat May 03 '20

NodeJS's worker threads are Pthreads.

2

u/HeinousTugboat May 03 '20

Is that it? You're gonna reply to me again later but not actually explain what it is you're going on about? Node threads are pthreads. If JavaScript doesn't have multithreading, what language does?

0

u/[deleted] May 03 '20

No JavaScript does not have multithreading. If you bind it to c it does... That's great but so can every other language BUT nothing in ecma script has multithreading. Async is not multithreading. Stop saying JavaScript is multithreaded. It's not. I could care less about some imported 3rd party package that everyone says not to use that is run from a completely different language that js attempts to bind to.

2

u/HeinousTugboat May 03 '20

Libuv is part of the core of node. It's not some imported 3rd party package. So JavaScript also doesn't have the ability to interact with the file system?

1

u/HeinousTugboat May 10 '20

1

u/[deleted] May 10 '20

Yeah it's the os regulating the child processes. You are just lobbing a process on another thread using c. I mean talk about not controlling things or it being in JavaScript.

The only reason I made this apparent is because everywhere online it's saying JavaScript is multithreaded and in parallel but the reality is it's either a call to c or binding to the browser. I even had this argument with some sites like tutorial point and stuff about dart and their answer is that this is a tutorial and not senior level.

But their the reason so many people were arguing me about this in this thread and it's just wrong in general.

1

u/HeinousTugboat May 10 '20

You know, you never did tell me what languages do have Multithreading with your definition. Even Rust defers to a package just like Node does. It's using part of its STD to spin up pthreads and that it lets the OS manage. ..just like Node does.

So what languages qualify in your book?

1

u/[deleted] May 10 '20

Actually Go has a scheduler control the goroutines. You don't control the threading or cpu because as your code grows the scheduler knows and controls them for you. There is a fine difference between async and actual parallel computing. Actual parallel computing are the processes literally running/starting/ending at exactly the same time. NOT locking, waiting, spinning off at different times. It is literally like two programs running at once, not you telling one to start and then the other. The added benefit of the scheduler knowing this is that as your program grows, you don't ever have to touch the goroutine again. Literally it scales as your scheduler tells it.

The issue with doing this in c++ and that, sure you get more control but now you have to maintain these threads, cpus, holding of memory, thread locking, ect every time someone makes a commit to your coroutine but in go you don't. You just don't forever on.

https://youtu.be/cN_DpYBzKso

1

u/HeinousTugboat May 11 '20

That was an interesting video, thanks. I find it interesting that they're very explicit that Goroutines aren't threads, but in fact are multiplexed into threads.

I think the problem here is the word "multithreading". To me, it means you can use multiple threads to do work. That's.. it. It seems that, to you, it implies that a language is highly concurrent and supports easy parallelism.

I'm not sure anyone's really tried to argue that JavaScript's a concurrent language. I know I certainly haven't, but it seems like that's what you're arguing, that it's not a concurrent language. Which is fair, it isn't. But it does support the concept of threads and multithreading. Whether that's parallel or not depends on the underlying implementation. In node, it can absolutely be parallel, running worker threads on different physical cores. But you're right, that's up to the kernel and scheduler to decide. That's true for Goroutines too, though. I'm not aware of any general purpose programming language that lets you coopt the kernel's scheduler.

My point is, you're not arguing that JavaScript isn't multithreaded and the argument you're making is basically redefining the concept of multithreading into nothing.

1

u/[deleted] May 11 '20

No JavaScript is not parallel. Binding it to c is or binding it to whatever the browser gives it is but JavaScript on it's own as a language does not run in parallel. It is concurrent in that it can lob logic into another thread but that's it. Go as a language is parallel and concurrent. It's in the language spec.

The problem with JavaScript's concurrency is that it is all controlled by the os. It itself has not much to do with threading besides letting the child processes spin off.

That's it. So stop calling JavaScript multithreaded and parallel. It can spin threads but that's it. You don't get anything more without 3rd parties, but that's again not JavaScript.

Here's an example of what you could do if it was.

https://divan.dev/posts/go_concurrency_visualize/

→ More replies (0)