An open-source C++ library developed and used at Facebook.
Switch branches/tags
v2018.09.17.00 v2018.09.10.01 v2018.09.10.00 v2018.09.03.01 v2018.09.03.00 v2018.08.27.00 v2018.08.20.00 v2018.08.13.00 v2018.08.09.00 v2018.08.06.00 v2018.07.30.00 v2018.07.23.00 v2018.07.16.00 v2018.07.09.00 v2018.07.02.00 v2018.06.25.00 v2018.06.18.00 v2018.06.11.00 v2018.06.04.00 v2018.05.28.00 v2018.05.21.00 v2018.05.14.00 v2018.05.07.00 v2018.04.30.00 v2018.04.23.00 v2018.04.16.00 v2018.04.09.00 v2018.04.02.00 v2018.03.26.00 v2018.03.19.00 v2018.03.12.00 v2018.03.05.00 v2018.02.26.00 v2018.02.19.00 v2018.02.12.00 v2018.02.05.00 v2018.01.29.00 v2018.01.22.00 v2018.01.15.00 v2018.01.08.00 v2018.01.01.00 v2017.12.25.00 v2017.12.18.00 v2017.12.11.00 v2017.12.04.00 v2017.11.27.00 v2017.11.20.00 v2017.11.13.00 v2017.11.06.00 v2017.10.30.00 v2017.10.23.00 v2017.10.16.00 v2017.10.09.00 v2017.10.02.00 v2017.09.25.00 v2017.09.18.00 v2017.09.11.00 v2017.09.04.00 v2017.08.28.00 v2017.08.21.00 v2017.08.14.00 v2017.08.07.00 v2017.07.31.00 v2017.07.24.00 v2017.07.17.01 v2017.07.17.00 v2017.07.10.00 v2017.07.03.00 v2017.06.26.01 v2017.06.26.00 v2017.06.19.00 v2017.06.12.00 v2017.06.05.00 v2017.05.29.00 v2017.05.22.00 v2017.05.15.00 v2017.05.08.00 v2017.05.01.00 v2017.04.24.00 v2017.04.17.00 v2017.04.10.00 v2017.04.03.00 v2017.03.27.00 v2017.03.20.00 v2017.03.13.00 v2017.03.06.00 v2016.12.19.00 v2016.12.12.00 v2016.12.05.00 v2016.11.28.00 v2016.11.21.00 v2016.11.14.00 v2016.11.07.00 v2016.10.31.00 v2016.10.24.00 v2016.10.17.00 v2016.10.10.00 v2016.10.03.00 v2016.09.26.00 v2016.09.19.00
Nothing to show
Clone or download
jesboat and facebook-github-bot add a comment about some sketchy behavior
`IOThreadPoolExecutor.pickThread()` has some sketchy behavior where, if the
threadpool has no threads, it returns `*thisThread_` unconditionally. My read
is that this can happen only in two cases.

First, `getEventBase` could be called from outside the threadpool while the
threadpool has no threads (either because it was stopped or because somebody
set it to 0 threads.) In this case, `*thisThread_` will be nullptr and
`getEventBase` will try to immediately dereference it, (hopefully) crashing.

Second, `getEventBase` could be called from inside the threadpool, but from a
thread which is shutting down. This is also somewhat dodgy, because by the time
we get to this case (`me && !contains(threadList_.get(), me)`), stopThreads
will have already called terminateLoopSoon on the evb. While it would still be
possible to use the evb safely (in the sense that one could write a program
which does not hit undefined behavior), I think it'd be strongly dependent on
the way IOTPE and EventBase are currently implemented and therefore probably a
bad idea.

I don't have the bandwidth to really dig into this now and figure out what the
correct behavior is, or how to fix people who might be relying on the broken
one. But I figure I can at least leave a comment behind that this is something
maybe worth looking into.

Reviewed By: meyering

Differential Revision: D9754314

fbshipit-source-id: 6851d49e634707cacc803a95763eda023967b932
Latest commit 34b79e4 Sep 19, 2018

Folly: Facebook Open-source Library

Build Status

What is folly?

Folly (acronymed loosely after Facebook Open Source Library) is a library of C++14 components designed with practicality and efficiency in mind. Folly contains a variety of core library components used extensively at Facebook. In particular, it's often a dependency of Facebook's other open source C++ efforts and place where those projects can share code.

It complements (as opposed to competing against) offerings such as Boost and of course std. In fact, we embark on defining our own component only when something we need is either not available, or does not meet the needed performance profile. We endeavor to remove things from folly if or when std or Boost obsoletes them.

Performance concerns permeate much of Folly, sometimes leading to designs that are more idiosyncratic than they would otherwise be (see e.g. PackedSyncPtr.h, SmallLocks.h). Good performance at large scale is a unifying theme in all of Folly.

Logical Design

Folly is a collection of relatively independent components, some as simple as a few symbols. There is no restriction on internal dependencies, meaning that a given folly module may use any other folly components.

All symbols are defined in the top-level namespace folly, except of course macros. Macro names are ALL_UPPERCASE and should be prefixed with FOLLY_. Namespace folly defines other internal namespaces such as internal or detail. User code should not depend on symbols in those namespaces.

Folly has an experimental directory as well. This designation connotes primarily that we feel the API may change heavily over time. This code, typically, is still in heavy use and is well tested.

Physical Design

At the top level Folly uses the classic "stuttering" scheme folly/folly used by Boost and others. The first directory serves as an installation root of the library (with possible versioning a la folly-1.0/), and the second is to distinguish the library when including files, e.g. #include <folly/FBString.h>.

The directory structure is flat (mimicking the namespace structure), i.e. we don't have an elaborate directory hierarchy (it is possible this will change in future versions). The subdirectory experimental contains files that are used inside folly and possibly at Facebook but not considered stable enough for client use. Your code should not use files in folly/experimental lest it may break when you update Folly.

The folly/folly/test subdirectory includes the unittests for all components, usually named ComponentXyzTest.cpp for each ComponentXyz.*. The folly/folly/docs directory contains documentation.

What's in it?

Because of folly's fairly flat structure, the best way to see what's in it is to look at the headers in top level folly/ directory. You can also check the docs folder for documentation, starting with the overview.

Folly is published on Github at

Build Notes


folly requires gcc 4.9+ and a version of boost compiled with C++14 support.

googletest is required to build and run folly's tests. You can download it from The following commands can be used to download and install it:

wget && \
tar zxf release-1.8.0.tar.gz && \
rm -f release-1.8.0.tar.gz && \
cd googletest-release-1.8.0 && \
cmake . && \
make && \
make install

Finding dependencies in non-default locations

If you have boost, gtest, or other dependencies installed in a non-default location, you can use the CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH variables to make CMAKE look also look for header files and libraries in non-standard locations. For example, to also search the directories /alt/include/path1 and /alt/include/path2 for header files and the directories /alt/lib/path1 and /alt/lib/path2 for libraries, you can invoke cmake as follows:

cmake \
  -DCMAKE_INCLUDE_PATH=/alt/include/path1:/alt/include/path2 \
  -DCMAKE_LIBRARY_PATH=/alt/lib/path1:/alt/lib/path2 ...

Ubuntu 16.04 LTS

The following packages are required (feel free to cut and paste the apt-get command below):

sudo apt-get install \
    g++ \
    cmake \
    libboost-all-dev \
    libevent-dev \
    libdouble-conversion-dev \
    libgoogle-glog-dev \
    libgflags-dev \
    libiberty-dev \
    liblz4-dev \
    liblzma-dev \
    libsnappy-dev \
    make \
    zlib1g-dev \
    binutils-dev \
    libjemalloc-dev \
    libssl-dev \

If advanced debugging functionality is required, use:

sudo apt-get install \
    libunwind8-dev \
    libelf-dev \

In the folly directory, run:

  mkdir _build && cd _build
  cmake ..
  make -j $(nproc)
  make install

OS X (Homebrew)

folly is available as a Formula and releases may be built via brew install folly.

You may also use folly/build/ to build against master:

  cd folly

OS X (MacPorts)

Install the required packages from MacPorts:

  sudo port install \
    autoconf \
    automake \
    boost \
    gflags \
    git \
    google-glog \
    libevent \
    libtool \
    lz4 \
    lzma \
    scons \
    snappy \

Download and install double-conversion:

  git clone
  cd double-conversion
  sudo make install

Download and install folly with the parameters listed below:

  git clone
  cd folly/folly
  autoreconf -ivf
  ./configure CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"
  sudo make install

Windows (Vcpkg)

folly is available in Vcpkg and releases may be built via vcpkg install folly:x64-windows.

You may also use vcpkg install folly:x64-windows --head to build against master.

Other Linux distributions

  • double-conversion (

    Download and build double-conversion. You may need to tell cmake where to find it.

    [double-conversion/] ln -s src double-conversion

    [folly/] mkdir build && cd build [folly/build/] cmake "-DCMAKE_INCLUDE_PATH=$DOUBLE_CONVERSION_HOME/include" "-DCMAKE_LIBRARY_PATH=$DOUBLE_CONVERSION_HOME/lib" ..

    [folly/build/] make

  • additional platform specific dependencies:

    Fedora >= 21 64-bit (last tested on Fedora 28 64-bit)

    • gcc
    • gcc-c++
    • cmake
    • automake
    • boost-devel
    • libtool
    • lz4-devel
    • lzma-devel
    • snappy-devel
    • zlib-devel
    • glog-devel
    • gflags-devel
    • scons
    • double-conversion-devel
    • openssl-devel
    • libevent-devel


    • libdwarf-dev
    • libelf-dev
    • libunwind8-dev