Freigeben über


Asynchronous and Synchronous are Subjective Terms

OK, this blog entry fits into the category of obsessive-compulsive...

Every time I hear somebody say "such-and-so is asynchronous", it kinda drives me nuts.  The same thing applies to synchronous.

The issue is that these terms describe the timing interactions between two things.  So, the I/O may be synchronous with respect to the calling thread...  That I get!   The I/O is not just plain synchronous.

My favorite example to help make this concrete lies in the SQL-OS.  This is the internal engine that implements MS SQL Server.   In the SQL-OS, there are Windows Threads and Fibers.  A fiber is just a call-stack with much lighter state than a full blown Windows thread and it is advanced by using a thread which gets associated with the fiber while the fiber is executing.  One of the cool things about fibers is that they may be executed on any of the threads in the process.

So, the SQL-OS has lots and lots of fibers.   It tends to create threads in a fashion correlated to the number of processors in the systems (I am not an expert here but the details are not the point).  There are a lot of fibers and a few threads.

When an operation is performed by SQL (say you are climbing down a BTree to get to a record which may involve some I/O), this is assigned to a fiber... that fiber is driven by a thread -- say Thread-T1.   If the work has to perform an I/O, the call stack of the fiber is suspended and Thread-T1 finds some other work to do.  When the I/O completes, it's time to get the blocked fiber going and ANY AVAILABLE THREAD is used to advance the fiber.  The work is completed by the fiber with the help of two threads.  

So, in my opinion, the I/O we just described is:
      Synchronous with respect to the fiber and
      Asynchronous with respect to the thread.

So, is that I/O "synchronous" or "asynchronous"?   The answer is BOTH, depending on which "with respect to" is being applied.   Subjective to the fiber's perspective, the I/O is synchronous.  Subjective to both threads' perspectives, the I/O is asynchronous (and, indeed, one thread launched the I/O and a different one handled the completion of the I/O).

Indeed, the word "synchronous" means "happening at the same time".   This is meaningless in the absence of both a subject and an object. 

Every single time I hear "asynchronous", it is normal for the subject to be bound: "The I/O is asynchronous".   It is also normal in our common usage for the object to be left unbound and only defined by the imagination (and shared assumptions) of the listener.  Most often, there is an assumption of a calling thread (specifically, a Windows thread) and that the subject (e.g. the I/O) is being contrasted to the amorphously defined "thread".

So, "asynchronous" and "synchronous" are both subjective terms.

Comments

  • Anonymous
    September 21, 2007
    I think you've made an issue where none really exists.  To me, the terms asnych and synch are always in the context of a call site.  Either the calling site does not proceed until the call returns, or it proceeds immediately from the call, and that's the difference between syncronous and asynchronous.    I'm not sure that distinction has any meaning in any other context.