小编joh*_*ohn的帖子

thread_local 变量在线程内不一致

我在文件 tracker.hpp 中有一个变量:

namespace TRIALS
{
    static thread_local int a = -1;
}
Run Code Online (Sandbox Code Playgroud)

我在 ema.hpp/ema.cpp 中的文件中有另一个名为 EMP 的类

namespace Algo
{
    class EMP
    {
        public:
            void Sample();
    };
}
Run Code Online (Sandbox Code Playgroud)
namespace Algo
{
    void EMP::Sample()
    {
        std::cout << "model " << std::this_thread::get_id() << " " << &TRIALS::a << " " << TRIALS::a << std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我的主文件


auto model = Algo::EMP();

void Simulate(const int a)
{
    TRIALS::a = a;
    model.Sample()
    std::cout << "worker " << std::this_thread::get_id() << " " << &TRIALS::a …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading thread-local

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

从熊猫中的每个其他时间戳减去每个组的最小时间戳

我有一个这样的DataFrame:

   Iter    ID       Time
0   1      A      12:00:00
1   1      B      12:00:01
2   1      C      12:00:01
3   2      B      12:02:00
4   2      A      12:02:02
5   2      C      12:02:06
6   3      C      12:05:01
7   3      B      12:05:00
8   3      A      12:05:05
Run Code Online (Sandbox Code Playgroud)

我想从每次迭代的最小时间戳中获取每个时间戳的偏移量。

例如,此示例的“ Delta”列可以为

   Iter    ID       Time       Delta
0   1      A      12:00:00    00:00:00
1   1      B      12:00:01    00:00:01
2   1      C      12:00:01    00:00:01
3   2      B      12:02:00    00:00:00
4   2      A      12:02:02    00:00:02
5   2      C      12:02:06    00:00:06
6   3      C …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas pandas-groupby

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