[-] program flow and structure clarification
by guydan - Sunday, 19 June 2016 12:03:54
Can you please explain to me once and for all the structure of the program?
The way I see it:

main sets global variables (c) ->
main calls start_scheduler(int t, int k) ->

scheduler calls initialize(length, width) (in coroutines.s)
(initialize = allocation of data structures + read state from file) ->

going back to the scheduler to start the main loop ->
looping... ->
...finished loop...
end_co (scheduler.s) ->
inside end_co: print final state
inside end_co: free all data structures
exit

this way the filename must be also a global variable, since we only pass t and k in the stack

does my structure fit the instruction? Ive been digging the forum and still some things aren't clear
[-] Re: program flow and structure clarification
by shimony - Sunday, 19 June 2016 13:44:39
No. Main gets the command-line arguments and calls a function that
does all the initializations. This function then: reads the input file and
sets global variables and arrays, and call init_co for ALL co-routines
INCLUDING all cells, printer, and scheduler.

THEN you start the scheduler (using a partial "resume"), and the scheduler
has its variables that maintain who is next (and resumes the other co-routines
accordingly until it is time to stop (final "resume" of printer), THEN calls end_co).


[-] Re: program flow and structure clarification
by guydan - Sunday, 19 June 2016 21:54:54
thanks.


Some following questions:

"Main gets the command-line arguments and calls a function that
does all the initializations"

1.By initialization you also means allocation, right?

2.Is the function located in "coroutines.s" file?
in the practical session we had a loop in the main for this purpose:

main() {
    /* initialize coroutines*/
    for(i =0; i < numco; i++)
        init_co_from_c(i);
    /* start a scheduler coroutine*/
    /* (where 2 is the scheduler's index... could be numco or numco+1 for us) */
    start_co_from_c (2);
}

3.How does the function receive the command-line arguments, as arguments to the function or by using the global variables (can be set in 'main')?
Re: program flow and structure clarification
by sadetsky - Sunday, 19 June 2016 22:56:22
1.By initialization we mean allocations and building of the initial states.
2.Yes
The main now should contain one more function, for allocation of all the needed structures.
3. The function of allocation gets the command-line arguments by reading them from the stack, and then sends these argument for each function that needs them. Length and width variables may be global.