标签: folly

递归变量声明

我刚刚在愚蠢/ ManualExecutor.h中看到了这个黑魔法

TimePoint now_ = now_.min();
Run Code Online (Sandbox Code Playgroud)

在我对整个库源代码进行grep之后,我还没有看到now_除此处之外的其他任何变量的定义.这里发生了什么事?这实际上是某种递归变量声明吗?

variables recursion c++11 folly

44
推荐指数
2
解决办法
2327
查看次数

在Windows上愚蠢

有没有人真的成功地在MSVC上使用Folly(例如fbvector等)类?

我无法找到任何明智的信息,例如,它无法编译因为没有找到folly-config.h,而我在网上找到的唯一的东西是github修订版,它"已被删除,因为它是由Configure自动创建的"和信息什么是这个配置以及如何启动它无处可寻.

c++ visual-c++ folly

13
推荐指数
0
解决办法
2170
查看次数

Pods/RCT-Folly/folly/portability/Time.h 和不同类型的 Typedef 重新定义中的错误('uint8_t'(又名'unsigned char')与'enum Clockid_t')

我正在审查 React Native 项目的源代码,但在构建它时遇到问题。

运行以下命令后

  1. npm install在项目的根部
  2. pod install在ios文件夹中

我在终端中收到以下消息:

sh: -c: line 0: syntax error near unexpected token `('

sh: -c: line 0: `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_12_0/' /Users/myUser/dev/ReactExplorerApp(Android)/ios/Pods/RCT-Folly/folly/portability/Time.h'
Run Code Online (Sandbox Code Playgroud)

当我使用 XCode 构建应用程序时,我在 Time.h (...Pods/RCT-Folly/folly/portability/Time.h) 处收到以下错误消息:

Typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')

该应用程序使用“react-native”:“0.66.1”。我正在使用 cocoapods 版本 1.11.2、node 版本 14.17.2 和 XCode 版本 13.1

Pod 文件内容:

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'ExplorerApp' do
  config = use_native_modules!
  pod 'GoogleSignIn'
  pod 'RNI18n', :path => '../node_modules/react-native-i18n'
  pod …
Run Code Online (Sandbox Code Playgroud)

ios react-native folly fbflipper

13
推荐指数
1
解决办法
1万
查看次数

C++20 协程的 Lambda 生命周期解释

Folly为 C++20 风格的协程提供了一个可用的库。

在自述文件中,它声称:

重要提示:您需要非常小心临时 lambda 对象的生命周期。调用 lambda 协程会返回一个 folly::coro::Task 捕获对 lambda 的引用,因此如果返回的 Task 没有立即 co_awaited 那么当临时 lambda 超出范围时,任务将留下悬空引用。

我尝试为他们提供的示例制作 MCVE,但对结果感到困惑。为以下所有示例假设以下样板:

#include <folly/experimental/coro/Task.h>
#include <folly/experimental/coro/BlockingWait.h>
#include <folly/futures/Future.h>
using namespace folly;
using namespace folly::coro;

int main() {
    fmt::print("Result: {}\n", blockingWait(foo()));
}
Run Code Online (Sandbox Code Playgroud)

我用地址消毒剂编译了以下内容,以查看是否有任何悬空引用。

编辑:澄清的问题

问题:为什么第二个示例没有触发 ASAN 警告?

根据cppreference

当协程到达 co_return 语句时,它执行以下操作:

...

  • 或为 co_return expr 调用 promise.return_value(expr),其中 expr 具有非 void 类型
  • 以与创建它们相反的顺序销毁所有具有自动存储持续时间的变量。
  • 调用 promise.final_suspend() 和 co_await 的结果。

因此,也许临时 lambda 的状态在返回结果之前实际上不会被破坏,因为foo它本身是一个协程?


ASAN 错误:我假设在等待协程时“i”不存在

auto foo() -> …
Run Code Online (Sandbox Code Playgroud)

c++ folly c++20 c++-coroutine

9
推荐指数
1
解决办法
1911
查看次数

Visual Studio编译std库中的错误

我正在尝试按照此处提供的说明松散地在Visual Studio 2015 RC中构建Facebook愚蠢:https: //github.com/jbandela/folly/tree/vc11

我希望通过2015年扩展的C++ 11支持,我可能比以前更容易.我一直在处理一个不错的剪辑问题,但我现在得到一组对我没有意义的编译错误.这是编译输出的顶部,第一个错误:

2>------ Build started: Project: folly, Configuration: Debug Win32 ------
2>  pch.cpp
2>  Unknown compiler version - please run the configure tests and report the results
2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(26): error C2143: syntax error: missing ',' before '<'
2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(26): error C2143: syntax error: missing ',' before '<'
Run Code Online (Sandbox Code Playgroud)

这是它带来的错误位置的源代码,同样在std命名空间的xstring中:

template<class _Mystr>
class _String_const_iterator
    : public _Iterator012<random_access_iterator_tag, // <---- line 26
        typename _Mystr::value_type,
        typename _Mystr::difference_type,
        typename _Mystr::const_pointer, …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ visual-studio-2015 folly

7
推荐指数
1
解决办法
2092
查看次数

来自并发哈希映射的迭代器是否安全?

我目前正在使用Facebook的并发哈希映射,我想知道这样的事情是否可行:

folly::ConcurrentHashMap<std::string, some_class> m;

// add some elements

const auto it = m.find("a");

// during this time, another thread removes the "a" element

if (it != m.end())
    it->second.something(); // it is now an invalid iterator
Run Code Online (Sandbox Code Playgroud)

在阅读了哈希映射的源代码后,我发现了这个:

迭代器持有返回元素的危险指针.只有在迭代器仍然有效时才能访问元素!

这是非常令人不安的,感觉使用任何返回的迭代器是不安全的,这是这样吗?

c++ multithreading folly

6
推荐指数
1
解决办法
334
查看次数

先前循环迭代对当前迭代执行时间的影响

我正在尝试测量folly哈希图中并发插入的性能。用于这种插入的程序的简化版本显示在此处:

#include <folly/concurrency/ConcurrentHashMap.h>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <vector>

const int kNumMutexLocks = 2003;
std::unique_ptr<std::mutex[]> mutices(new std::mutex[kNumMutexLocks]);
__inline__ void
concurrentInsertion(unsigned int threadId, unsigned int numInsertionsPerThread,
                    unsigned int numInsertions, unsigned int numUniqueKeys,
                    folly::ConcurrentHashMap<int, int> &follyMap) {
  int base = threadId * numInsertionsPerThread;
  for (int i = 0; i < numInsertionsPerThread; i++) {
    int idx = base + i;
    if (idx >= numInsertions)
      break;
    int val = idx;
    int key = val % numUniqueKeys;
    mutices[key % …
Run Code Online (Sandbox Code Playgroud)

c++ time stl c++11 folly

6
推荐指数
1
解决办法
264
查看次数

为什么我们需要使用 folly::fbvector 而不是 std::vector 和分配器,最初保留大的未提交区域?

众所周知,如果我们将元素 push_back 到std::vector<>,并且如果向量中分配的整个内存都被占用,则std::vector<>保留当前内存大小的 2X(分配 2X 大小的新内存),调整向量大小并将旧数据复制到新内存。

我们可以优化它,Facebook 在 folly-library 中做到了这一点(FBVector 是 Facebook 对 std::vector 的直接实现。它有特殊的优化用于可重定位类型和 jemalloc https://github.com/facebook/folly/ blob/master/folly/FBVector.h#L21)。

即当vector<>没有足够的内存来 push_back 新元素时,然后我们分配更多的内存,但不会增加 2 倍(不同的次数:1.3 - 1.5 次

说明:https : //github.com/facebook/folly/blob/master/folly/docs/FBVector.md

下面的图形求解器显示,选择 k = 1.5(蓝线)允许在 4 次重新分配后重用内存,选择 k = 1.45(红线)允许在 3 次重新分配后重用内存,选择 k = 1.3(黑线)允许仅在 2 次后重用重新分配。

在此处输入图片说明

但是为什么我们需要使用folly::fbvector<>而不是std::vector<>使用我们的自定义分配器VirtualAllocEx()(如下所示:我需要使用 VirtualAlloc/VirtualAllocEx 的原因是什么?),或者在 linux 中使用相同的/sf/answers/194803731/ 1558037,其中:

  • std::vector<>::reserve() - 最初保留大量未提交的虚拟地址区域(分配 WMA,但在 PT 中不分配任何 PTE),例如最初分配 16 GB …

c++ posix memory-management vector folly

5
推荐指数
1
解决办法
2212
查看次数

愚蠢的 IOThreadPoolExecutor 与 CPUThreadPoolExecutor

我正在尝试更多地了解我正在处理的这个代码库使用的异步抽象。

我读Folly的文档两个异步执行池库,IOThreadPoolExecutor用于io绑定的任务,并CPUThreadPoolExecutorcpu密集型任务(https://github.com/facebook/folly/blob/master/folly/docs/Executors.md)。

我正在阅读描述,但我不明白主要区别。它似乎IOThreadPoolExecutor是围绕event_fdepoll循环构建的,并CPUThreadPoolExecutor使用队列和信号量。

但这并没有告诉我太多的好处和权衡。

c++ linux folly

5
推荐指数
1
解决办法
243
查看次数

使用护目镜时如何避免警告?

我正在使用愚蠢的范围保护,它正在工作,但它会生成一个警告,说该变量未使用:

warning: unused variable ‘g’ [-Wunused-variable]
Run Code Online (Sandbox Code Playgroud)

代码:

folly::ScopeGuard g = folly::makeGuard([&] {close(sock);});
Run Code Online (Sandbox Code Playgroud)

如何避免这种警告?

c++ scopeguard c++11 folly

4
推荐指数
1
解决办法
687
查看次数

Folly 项目的 Cmake 文件

我正在尝试编写一个玩具示例来使用 Facebook 的Folly 。该程序引入如下:

#include <utility>
#include <iostream>
#include <folly/Format.h>
#include <folly/futures/Future.h>
#include <folly/executors/ThreadedExecutor.h>
#include <folly/Uri.h>
#include <folly/FBString.h>

static void print_uri(const folly::fbstring &address)
{
  const folly::Uri uri(address);
  const auto authority = folly::format("The authority from {} is {}", uri.fbstr(), uri.authority());
  std::cout << authority << std::endl;
}

int main()
{
  folly::ThreadedExecutor executor;
  folly::Promise<folly::fbstring> promise;
  folly::Future<folly::fbstring> future = promise.getSemiFuture().via(&executor);
  folly::Future<folly::Unit> unit = std::move(future).thenValue(print_uri);
  promise.setValue("https://conan.io/");
  std::move(unit).get();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题是我不确定编译这样的程序所需的库是什么。CMakeList.txt如果有人可以共享项目文件,我将非常感激Folly

c++ folly

2
推荐指数
1
解决办法
3283
查看次数