subhankar katyayan wrote:
> Dear All,
> 
> Could you please look into the code snippet and let me know why it's giving 
> core and what should be the probable solution for this....
> 
> #include <stdio.h>
> 
> #define buffer_size 2000000000
> #define num_writers 300
> #define num_readers 500
> 
> int main()
> {
>         char *ptr;
>         char *shmptr[num_writers];
>         int i, numr, numw, nump;
> 
>         unsigned long cksum = 0;
> 
>         numr = nump % num_readers;
>         numw = nump - numr;
>         numw = numw / num_readers;
>         ptr =  shmptr[numw];
> 
> 
>         for(i = 0; i < buffer_size; i++)
>          cksum += *ptr++;
> 
> }
> 
> skumar

Among other things, 'nump' doesn't appear to be initialized.  Your 
compiler should be warning you about that.  If not, turn up the warning 
level until it does.

Also, a debugger would have caught what the compiler missed.  Stepping 
through the code will likely reveal that 'nump' gets assigned some 
bizarre number.

Finally, your for-loop is likely going to step on some memory your 
program isn't allowed to access for any reason whatsoever.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to