+ 3

Spin lock - need | C++ header files | windows

Hi As we can implement our own linked list or vector or queue data structure, C++ has already given library for all these containers. Do we have some header and default implementation for C++ windows spin lock or not ? Any example code of library usage ? One more question is on need of spin lock. Is it better than mutex or not ?

20th Feb 2023, 3:13 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Antwort
+ 2
Ketan, You don’t need a header to implement a spinlock - although easier to make use of the atomic library. In most cases you’d be better off with a mutex, unless you have a specific reason for using a spinlock. Mutex’s tend to be faster and allow other threads to run - although can be a bit more weight on the cpu with putting the threads to sleep/waking.
20th Feb 2023, 4:26 PM
DavX
DavX - avatar