I am confused by the function of spin lock.
The spin lock is used to stop the process from re-scheduling. However, in a machine with just one core, is it useful to use s
Short answer: no.
According to http://uw714doc.sco.com/en/man/html.3synch/Intro.3synch.html
Spin locks must not be used on a single processor system. In the best case, a spin lock on a single processor system will waste resources, slowing down the owner of the lock; in the worst case, it will deadlock the processor.
From: http://blogs.microsoft.co.il/blogs/sasha/archive/2008/08/10/practical-concurrency-patterns-spinlock.aspx
On single-processor systems, spinlocks are not needed because spinlock synchronization is required on high IRQLs only. On high IRQLs (above dispatch IRQL) a context switch cannot occur, so instead of spinning the acquiring thread can simply request an interrupt on the relevant IRQL and return; the interrupt will be masked until the releasing thread lowers the IRQL below the requested IRQL.
For single processor systems, the kernel will ignore the spin count value, and treat it as zero - essentially making a spinlock a no-op.
Yes, spin locks can be useful, and improve efficiency of some operations. However, generally you should start with a mutex, and if profiling show it to be a bottleneck, you may want to consider a spinlock.