2

I already know when calling an asynchronous method e.g. myAsync(), the caller e.g. Caller() can continue executing without waiting for it to be finished. But on the other hand, myAsync() also is executing.

public void Caller(){              
    myAsync();---------------------running
    dosometing();------------------running
}

The code next to myAsync() in Caller() will execute with myAsync() at the same time. So could this situation be considered as a kind of concurrency?


update

I prefer use javascript and c#

qslcna
  • 107
  • 1
  • 10
  • See this ....... http://stackoverflow.com/questions/4844637/what-is-the-difference-between-concurrency-parallelism-and-asynchronous-methods – AntDC Nov 17 '16 at 11:29
  • Are you interested in a particular programming language? (If so, add that to your question.) – Tim Grant Nov 17 '16 at 11:31

1 Answers1

0

That very much depends on the concurrency model of your programming language.

If your language allows you to define methods that are "implicitly" running in parallel; then of course, calling myAsync() would use some kind of "concurrency mechanism" (for example a thread) to do whatever that method is supposed to do.

In that sense, the answer to your question is yes. But it might be important to point out that many "common" programming languages (such as Java) would only "work" in such a context when myAsync() would be creating some thread to then run "something" using that thread.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • thanks for you answer :), Is there any way to call an asynchronous method without concurrency or without creating a new thread – qslcna Nov 17 '16 at 12:48
  • I know what you mean _**run "something" using that thread**_. something will be callback of myAsync(), right? In C# it is. @GhostCat – qslcna Nov 17 '16 at 16:35
  • No, I mean that myAsync() could start a thread ... and give that thread some method/callback to run. Again: your code example is just invoking a method. At least in Java *invoking* a method always happens on the same thread ... but maybe that method itself triggers a new thread, and instructs that thread to do something. – GhostCat Nov 17 '16 at 16:37
  • I just see the [link](http://stackoverflow.com/a/28860490/5954068). Seem C# would rewrites dosomething() as a callback that will be called upon completion of the myAsync() using the thread create by myAsync() . @GhostCat – qslcna Nov 17 '16 at 16:46
  • Read your answer again, I think I get your point now :) your *something* is something in myAsync() will execute, not the dosomething() method :( @GhostCat – qslcna Nov 17 '16 at 16:54
  • Exactly. Hope that helped. – GhostCat Nov 17 '16 at 18:16