# 单个位的 spinlock 实现 folly::PicoSpinLock

N.B. You most likely do not want to use PicoSpinLock or any other kind of spinlock. Consider MicroLock instead.

In short, spinlocks in preemptive multi-tasking operating systems have serious problems and fast mutexes like std::mutex are almost certainly the better choice, because letting the OS scheduler put a thread to sleep is better for system responsiveness and throughput than wasting a timeslice repeatedly querying a lock held by a thread that's blocked, and you can't prevent userspace programs blocking.

Spinlocks in an operating system kernel make much more sense than they do in userspace.

Q. E. D.

##### 类似文章：

folly::fbstring是一个完全兼容std::string的类，可以做到无缝替换，而且性能更高。其代码参见https://github.com/facebook/folly/blob/master/folly/FBString.h

follyLikely.h文件提供了 LIKELY 和 UNLIKELY 宏，提示编译器在分支预测时选择分支。其实现很简单

folly::dynamic提供类似于C++的动态类型。和std::any可以容纳任意类型不一样，folly::dynamic只支持保存以下几种类型：