c - How can Multiprocessing be achieved by Programming Languages? -
i trying develop simple operating system. till programs developed can run in single processor. when went through concept called multiprocessing systems of latest systems based, got lot of doubts.
first, how can create program can run in multiprocessor systems. hardware oriented or programmer specific?
second went through parallel programming languages can helpful in multiprocessing systems java 1 c not. how can os developed in c(windows) can achieve multiprocessing?
thanks.
you're right: typical c program single-processor. statements write in expected executed 1 after other, obeying loops , tests required. can call function in c says "don't execute function now: create new thread , execute that!"
int maxplaces; int pidigits; void calculatepi() { // write code calculate pi maxplaces // update pidigits go } // calculatepi() int main() { maxplaces = 2000000000; // calculatepi(); // old code: don't this! instead, do... startthread(calculatepi); while (pidigits<=maxplaces) { print(pidigits); } // while } // main()
if execute code old code, without using (made-up) function startthread()
, program hang long time print out number 2000000000 when finished.
but function startthread()
tells os create new thread of execution on function calculatepi()
, return immediately. means main()
can start repeatedly print out values of pidigits
gets larger. there 2 threads of execution: 1 calculating digits of pi, other printing out how far it's got.
this program work on multi-threaded os, running single processor. in case each thread little bit of processor time before swapped other. if computer has multiple processors, os might give 1 thread 1 , other other - program doesn't care or (usually) know.
parallel programming languages, however, written such don't have explicitly create new threads of execution this. syntax , design of language makes obvious when tasks can run concurrently. c isn't that, can still take advantage of concurrency special function calls.
Comments
Post a Comment