Thursday, February 07, 2008

Some more 'C'

in shared memory IPC in C, if you share a pointer does that mean that you share the memory location pointed by the pointer, no, after many hours of debugging a code, where a program shared an array of pointers with its child process, the child process calculated Fibonacci series and updates the array pointed by the pointer which is in shared memory location, after the child process ends, when we tried to access the array, the famous GCC report "segmentation fault".

A multithread program to calculate Fibonacci series, if every thread waits for the output of previous thread (assuming, that each thread calculates fixed number of elements in the series), then why the hell you need a multi-threaded program, so we all know that there is a formula to calculate nth number in Fibonacci series, and iterative calculation is better than formula, so what do we do.
Split the range so each thread can calculate some amount of numbers, in every thread use the formula to find the first and second number and iterate to find others.

1 comment:

Anonymous said...

cant understand the concept of pointers being shared but not the memory but.... u can avoid this problem by not doing assignments given by Prof Rao to juniors... :D