What is synchronous and asynchronous function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kp7796
    New Member
    • Aug 2009
    • 8

    What is synchronous and asynchronous function?

    What is synchronous function?
    What is asynchronous function?

    Unsigned char a=0;
    Void function (void ){
    Unsigned char Flag;
    Flag=0
    If (a==1){
    Flag=1;
    }
    Return (Flag)
    }

    EI()__external interrupt
    {
    a=1;
    }
    Can you please let me know above function is synchronous or asynchronous?
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Hi.

    Synchronous method call wait for the method to complete before continuing with program,asynchr onous method call will return immediately and program can perform other operations. Called method will work independently.


    Regards
    Dheeraj Joshi

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by kp7796
      What is synchronous function?
      What is asynchronous function?

      Unsigned char a=0;
      Void function (void ){
      Unsigned char Flag;
      Flag=0
      If (a==1){
      Flag=1;
      }
      Return (Flag)
      }

      EI()__external interrupt
      {
      a=1;
      }
      Can you please let me know above function is synchronous or asynchronous?
      This isn't even valid C; please post readable questions, don't just dump ill formatted snippets here and expect your readers to be psychic. Read about code tags and how to use them and proofread your own question before you post it.

      kind regards,

      Jos (moderator)

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        There is no such thing as a synchronous or asynchronous function. All functions are called execute and finish.

        There are asynchronous operations, that is operations that you call a function to start but where the start function returns immediately and the operation makes some sort of callback to your code when it completes to give its completion status.

        What you appear to have there is a normal function and an interrupt routine. I have heard interrupt routines refered to as many things, notably both foreground and background processing. None of these terminologies are standard. What is important is that you understand how an interrupt routine works and what restrictions it places on the program as a whole.

        Any processor has interrupts, that is external inputs that can fire at any time during processing. When an enabled interrupt fires during processing what normally happens is the processor stores the current state of processing on the stack and jumps directly to a special routine (function), the interrupt handler which it executes. When that function finishes the processor restores the processing state from the stack and continues.

        Interrupt routines are typically short so that they run quickly because they often have to respond directly to hardware events.

        The effect on your programming is that you have to make sure that any functions you wish to call from your interrupt routine are written so that they can be called from an interrupt routine. Sometimes this means giving them special prototypes and in such cases it is not unheard of to have 2 versions of the same function, 1 to call from normal processing and 1 to call from interrupt routines.

        However more importantly it is normal for interrupt routines to alter data to indicate the interrupt happened in some way. It is very important that this data is protected from dual access, that is the program trying to read it while the interrupt routine writes it or worst still the program trying to write it while the interrupt routine writes.

        In the first case you may get strange control decisions in the second case you may corrupt program data.

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          In what context did you hear the terms synchronous function and asynchronous function?

          Comment

          Working...