It looks OK from the information given. The way I see it, probably one of two things is happening:
(1) That the number of CPUs is, in fact, 1 and not 4.
(2) You are going out of bounds of one the arrays you are accessing, causing some sort of undefined behavior.
This is where using a debugger is a vital skill. With a debugger, you can step through your code line by line and pinpoint exactly where behavior starts to diverge from what you expect. Then you can look at the state of variables at that moment and see what exactly what data differs from what you expect.
Also, g_pShmBuf is a pointer; if it has the value of 4, then something is probably wrong. I know you meant "g_pShmBuf->cpus" but it's good to be precise in your details.
"g_pShmBuf" I take it this means "global pointer to a buffer of shared memory".
If you are sharing memory between different threads or processes, then perhaps something is going wrong there.