5

I read this question Asynchronous vs Multithreading- is there a difference and search in Google about differences.

What is the benefit to use Asynchronous instead of Multithreading? and when use Asynchronous instead of Multithreading?

Community
  • 1
  • 1
  • 5
    They're not competing options, a better question might have been "when to use which" but either way it's not a good question for SO. – H H Mar 17 '13 at 10:52
  • "Asynchronous instead of Multithreading?" is misleading, because a common method to accomplish asynchronicity [and also parallelism] is with multithreading. Let me give you another word to investigate: concurrency. – Theraot Mar 17 '13 at 11:01
  • 1
    @Theraot you can edit my question\ –  Mar 17 '13 at 11:03
  • @Shahrooz Jefri yes, I can. And I choose not to. I consider this question shouldn't be here, In my opinion it is too broad, open for discussion, and misleading. Still I recognize the need of information, so I won't flag or downvote. Instead I would try to help before it gets closed. I recommend you the talk "Concurrency Is Not Parallelism" by Robert Pike available at: http://vimeo.com/49718712. – Theraot Mar 17 '13 at 11:11

1 Answers1

3

If your task can be done using asynchronous programming, the it is better to do it that way instead of going for multi-threaded programming. for 3 reasons:-

1: Perfomance

In multi-threading, the CPU or w/e has to keep switching between threads. So, even if your thread is doing nothing and just sitting there (or more likely, doing a comparison to see if a condition is true so it can get one with doing with w/e it was created to do), the CPU still switches threads and the process takes some time. I don't think that would be very bad, but your performance surely takes a hit.

2: Simplicity & Brevity

Also, maybe it's just me, but asynchronous programming just seems more natural to me. And before you ask, no, I'm not a fan of JS but still. Not only that, but you run into problems with shared variables and thread-safeness and others — all of which can be side-stepped by using asynchronous programming and callbacks.

3: Annoying implementations of threads

In Python there's this really horrible thing called a GIL (Global Interpreter Lock). Basically, Python doesn't let you actually run concurrent threads. Also, if you're thinking about running a threaded program on a multi-core CPU, forget it.

There might be caveats in C# too, I don't know. These are just my 2 cents...


All that said, asynchronous and multi-threading are really not that comparable. While multi-threading may be used (inefficiently) to implement asynchronousity, it is a way to get concurrency and acynhrounousity is a programming style, like OOP (Object Oriented Programming).

Yatharth Agarwal
  • 4,385
  • 2
  • 24
  • 53