How to implement from scratch asynchronous single threaded tasks in C

Viewed 128

As far as I know there are four kinds of program executions:

1) Synchronous (one thread):

Synchronous (one thread):

1 thread ->   |<---A---->||<----B---------->||<------C----->|

2) Synchronous (multi-threaded):

thread A -> |<---A---->|   
                        \  
thread B ------------>   ->|<----B---------->|   
                                              \   
thread C ---------------------------------->   ->|<------C----->| 

3) Asynchronous (one thread):

         A-Start ------------------------------------------ A-End   
           | B-Start -----------------------------------------|--- B-End   
           |    |      C-Start ------------------- C-End      |      |   
           |    |       |                           |         |      |
           V    V       V                           V         V      V      
1 thread->|<-A-|<--B---|<-C-|-A-|-C-|--A--|-B-|--C-->|---A---->|--B-->| 

4) Asynchronous (multi-Threaded):

 thread A ->     |<---A---->|
 thread B ----->     |<----B---------->| 
 thread C --------->     |<------C--------->|
  • Start and end points of tasks A, B, C represented by <, > characters.
  • CPU time slices represented by vertical bars |

But the only one that I don't know how to implement from scratch is the single threaded asynchronous execution. I'd like to know how to implement something similar (without threads) in a low level language from 0 like C if its possible.

0 Answers
Related