If you're looking for an example, take a look at the MatrixBase class here:
Put the MatDestroy in your destructor.
Your logic for setting elements is completely wrong. The easiest solution is:
for ( .... i .... )
for ( ... j ... )
globalnumber = .... i ... j ....
if ( globalnumber>=low && globalnumber<high )
spinlocks are bad because other threads in other processes could have used the CPUs. And yes, from the OS point of view, the polling thread is always in the running state which prevents the CPU from tuning down the clock to save electricity. An ideal implementation would make the thread waiting on some sync object and be notified when data arrives.