Question

I have a system which consists of multiple threads, lets say process A, B and C and these processes are completely written in SDL which eventually gets converted to C language after compilation.

I also have an equivalent simulation environment with the same processes, which would run on only one thread but simulate each of these processes. Basically, each of the processes A, B and C get recompiled with a different set of options and somehow everything works as one process (typical of IBM-SDL simulation). This theoretically represents a light-weighted system of the real process and everything works as one process. Now in this simulation environment, There are three files lets that get generated, lets say :- A.c B.c and C.c. Obviously in this simulation, there is no room for pre-emption of a process. If a message X comes to process A, A would completely process this signal and then go to the next state transition and ONLY then the next process would be running when next signal comes in to the system.

I am trying to implement pre-emption in this simulation system without threads. As it turns out, in simulation each of these files can be edited (via some script) and I know the exact possible pre-emption points during the course of execution of a particular set of signals one after another.

My question is :- If I insert conditional goto / break statements (after lets assume every line in each A.c, B.c and C.c) and jump from one file to another during the code execution, have I implement a simulated threaded environment ?

Or Am I missing something here ?

I know its a very broad question and my OS knowledge is not great. Also, I know that there can be many conditions possible for such a scenario to work. But lets assume I find a way to fix those problems. My question boils down to this :- If "smart" goto can be equivalently used as a substitute for Multiple threads in single threaded environment ?? Timing is not a problem for me, as I am working with a simulated time. System load etc, don't matter. I was thinking of adding a control function call after every step in each of these files A.c, B.c and C.c and in this control function I can check if i want to return, or jump to some other place and continue to execute from another file. What kind of implementation difficulties would I face in such an approach ?

Was it helpful?

Solution

It kind of sounds like you are talking about cooperative multitasking, which is how the first versions of Windows worked. Processes didn't just get to run as long as they wanted, and get preempted by the OS; they would run for some period of time, then "yield" control back to the OS, who would schedule another application to run.

This kind of thing can still work within the context of a single thread. It's called a Fiber. Fibers are like lightweight threads; they work by cooperatively yielding execution to another fiber, instead of relying on the OS to perform the task switch. The benefit is the reduction of the overhead that is usually incurred with a task switch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top