0
         //main
         Scheduler::start(0, 2, emptyTask, true, false);

This is the head file for a function with a static function called 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);
         };
        ...

        }

This is the class file and the code stops printing out when I try to intiallze the the static FiberPool pointer. The code hangs and doesn't execute the constructor. (con_cout is a custom version of 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)
    }

        ...
   }

This is FiberPool

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;
}

This is the output:

//output
        scheduler before fbrpool!!
        before new fbrpool 1

Using Visual Studio 2013 on window 7. This compiles and runs perfectly if the code is all in one project. But when I have separate projects is the problem. Calling Scheduler::start(..) from my main in the second project makes this issue of compiling and then stopping execution.

I get no error messages with the debugger and windows doesn't try to end the process. My CPU in core 1 is always at maximum usage and at this point in the program there is only 1 thread (the main thread).

I have tried both static and dynamic linking but neither worked. With dynamic linking I had the linker set up and used Dynamic __declspec( dllexport ). I have references and additional include directories too. All the other code in my so called "library" work except this. Just to note I have not used the keyword friend.

Geff
  • 52
  • 1
  • 5
  • Does it still hang if you remove all your `con_cout` calls? – paddy Mar 16 '16 at 13:03
  • yeah, con_cout is a thread safe version of cout. I have been working with this project alot and it's only causing this problem when I have the code in 2 seperate projects – Geff Mar 16 '16 at 13:05
  • Since the problem occurs when using as a DLL, you should really show your _actual_ code with the relevant `__declspec(dllexport)` and `__declspec(dllimport)` storage classes. – paddy Mar 16 '16 at 13:13
  • When i was doing dll headers i only did the __declspec(dllexport) could the problem be the fact i didn't use __declspec(dllimport) . However this error also happens with static linking, the example above is the static linking version – Geff Mar 16 '16 at 13:18

0 Answers0