//main
Scheduler::start(0, 2, emptyTask, true, false);
这是带有名为 start() 的静态函数的函数的头文件
//scheduler.h
namespace fbr{
static FiberPool *fiberPool;
...
class Scheduler{
public:
static void start(const unsigned int FIBER_COUNT,
const unsigned int THREAD_COUNT,BaseTask* startingTask, bool
fibersAreDynamic, bool enableSleeping);
};
...
}
这是类文件,当我尝试初始化静态 FiberPool 指针时,代码停止打印。代码挂起并且不执行构造函数。(con_cout 是 std::cout 的自定义版本)
//scheduler.cpp
void Scheduler::start(const unsigned int FIBER_COUNT, const unsigned int THREAD_COUNT,BaseTask* startingTask, bool fiberAreDynamic, bool enableSleeping){
...
con_cout << "scheduler before fbrpool!!" << fbr::endl; //this prints out
//construct FiberPool and its fibers
//if dynamic make sure there is at least 1 fiber per worker
if (useDynamicFibers && FIBER_COUNT < THREAD_COUNT){
con_cout << "before new fbrpool 1" << fbr::endl; //this prints out
fiberPool = new FiberPool(THREAD_COUNT); //code stops here for some reason when creating a new FiberPool within start (a static function)
}
...
}
这是光纤池
namespace fbr{
public:
//constructor apparently is never called
FiberPool::FiberPool(const unsigned int FIBER_COUNT){
fbr::con_cout << "fiberpool!!" << fbr::endl;
for (unsigned int i = 0; i < FIBER_COUNT; i++)
fibers.push_back(new Fiber(i));
}
...
private:
//list of all the fibers available
con_vector<Fiber *> fibers;
}
这是输出:
//output
scheduler before fbrpool!!
before new fbrpool 1
在窗口 7 上使用 Visual Studio 2013。如果代码都在一个项目中,这将完美地编译和运行。但是当我有单独的项目时,问题就来了。在第二个项目中从我的 main 调用 Scheduler::start(..) 会产生编译然后停止执行的问题。
我没有收到调试器的错误消息,并且 Windows 不会尝试结束进程。我在核心 1 中的 CPU 始终处于最大使用率,此时程序中只有 1 个线程(主线程)。
我尝试过静态和动态链接,但都没有成功。通过动态链接,我设置了链接器并使用了 Dynamic __declspec( dllexport )。我也有参考资料和其他包含目录。我所谓的“库”中的所有其他代码都可以工作,除了这个。请注意,我没有使用关键字朋友。