0

I've recently been trying to learn about threading, thread safety and come across the very large term 'asynchronous programming'. It totally threw me into confusion and wondered if anyone could clear up some questions I have about it, as it really has confused me.

Before this, I thought the definition of "asynchronous" was that is wouldn't be occurring at the same time, and the term for occurring at the same time would be "synchronous".

If you google, it says exactly that actually, but now I learn asynchronous programming is all about 2 things happening at once, at least that's what it seems to me.

I've been watching a youtube video series about it all and they explained that asynchronous in programming is all about running multiple things without affecting the main UI thread.

Now, I understand threading, you make a new thread and it gets added to the thread pool, threads are ran depending on the amount of cores on your computer, and they're all run for a very short amount of time, to create the illusion that all threads are running in parallel.

The thing that's tripped me up is asynchronous programming, and now I get told that making a new task is asynchronous programming, does asynchronous programming just mean that your coding on new threads, because as of now the only way 2 operations are running at the same time is when they're running on 2 other threads not including the main thread (UI thread). Now I'm wondering what else makes threads.. is it the fact that it run on its own thread that makes it part of asynchronous programming or am I missing a big chunk of it?

Can anyone clear this up for me?

game
  • 25
  • 2
  • Read this: https://blogs.msdn.microsoft.com/benwilli/2015/09/10/tasks-are-still-not-threads-and-async-is-not-parallel/ – Sam Marion Dec 03 '17 at 02:55
  • _[Asynchronous Programming with Async and Await](https://msdn.microsoft.com/en-us/library/hh191443(v=vs.120).aspx)_ –  Dec 03 '17 at 03:12
  • 1
    _[What is the difference between asynchronous programming and multithreading?](https://stackoverflow.com/questions/34680985/what-is-the-difference-between-asynchronous-programming-and-multithreading)_ - this one you will probably like more than my other link –  Dec 03 '17 at 03:13
  • 1
    The letter `'a'` in front of a word modifies into to mean "without". For example, "amoral" means "lacking a moral sense; unconcerned with the rightness or wrongness of something." So "asynchronous" mean without being sychronised. There is no specific ordering of events or relationship to each other. – Enigmativity Dec 03 '17 at 04:32
  • Also, it is entirely possible to write asynchronous code that runs on a single thread only. Multi-threading is asynchronous, but asynchronous is **not** multi-threading. – Enigmativity Dec 03 '17 at 04:34

1 Answers1

7

"Asynchronous programming" doesn't quite mean "not happening at the same time"; rather, it means "not synchronized", and from a programming perspective that means you can't assume anything about the order in which things happen between two things that are asynchronous.

Multiple threads can be asynchronous, but so can, for example, multiple processes on possibly multiple machines.

Warren Dew
  • 8,790
  • 3
  • 30
  • 44