Lockfree ThreadPool implementation How could this template class ThreadPool be improved?

I use Boost queue to keep std::function's numbers from std::array(simple hashing) from which I can later retrieve the std::function's objects to execute them with operator(). 
It's not possible to store them directly in boost::lockfree::queue (Stored Object Type must have non-trivial destructor).

That's why I emulate primitive lockfree container with std::array&lt;std::pair&lt;int , ...&gt;.
The GuarderArray template class lacks garbage collector. 

#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;mutex&gt;
#include &lt;memory&gt;
#include &lt;atomic&gt;
#include &lt;functional&gt;
#include &lt;boost/lockfree/queue.hpp&gt;
#include &lt;array&gt;


using std::cout ; using std::cin; using std::endl;
using std::mutex; using std::atomic;
using std::array; using std::function;

template &lt;int NN&gt; using guardedArray =  std::array&lt;std::pair&lt;std::atomic&lt;bool&gt;,std::function&lt;void()&gt;&gt;, NN&gt; ;

template &lt;typename T&gt; using lockfreequeue = boost::lockfree::queue&lt;T,boost::lockfree::capacity&lt;1000&gt;&gt;;

class Functor{
    int myNN;
public:
    Functor(int nn):myNN(nn){};
    Functor(std::function&lt;void()&gt; ff) : myff(ff){};
    std::function&lt;void()&gt; myff;
    Functor(const Functor&amp;) = default;
    Functor operator=(const Functor&amp;) ;
    ~Functor() = default;
    void operator()(){
    myff();

    }
};



template &lt;int NN &gt; class GuardedArray{
    guardedArray&lt;NN&gt; myGuardedArray; 
public:
    int insertObject(std::function&lt;void()&gt; ff){
    int kk ;
    bool empty;

    do{
    kk = rand () % NN;
    empty = myGuardedArray[kk].first;
    cout &lt;&lt; "spining ... " &lt;&lt; endl;


    }while(!(std::atomic_compare_exchange_weak(&amp;myGuardedArray[kk].first,&amp;empty,true)));
    myGuardedArray[kk].second = ff;
    return kk;
    };
    std::function&lt;void()&gt; getIndex(int ii){return myGuardedArray[ii].second  ; };
    std::thread garbageCollectorThread;



};

template &lt;int NN &gt; class ThreadPool{

private:
    std::thread tt[NN];
    GuardedArray&lt;1000&gt; myGA;
    bool endFlag;
public:
    ThreadPool():endFlag(false){

    for(int ii = 0 ; ii &lt; NN ; ++ii){       
        std::thread localThread(&amp;ThreadPool&lt;NN&gt;:: threadLoop, this);
        tt[ii].swap(localThread);

    }

    };
    void bookTask(std::function&lt;void()&gt; ff){
    int ii = myGA.insertObject(ff);
    mySync.push(ii);
    };

    bool demandedAccess[NN];
    int waitingProcess;
    ~ThreadPool() {endFlag = true; for (int ii = 0 ; ii &lt; 10 ; ii++  ){  tt[ii].join();}   };
    int myWrapper();
    void threadLoop();
    lockfreequeue&lt;int&gt; mySync;

};

template &lt;int NN&gt; void ThreadPool&lt;NN&gt;::threadLoop(){
    std::thread::id kk  = std::this_thread::get_id();
    std::function&lt;void()&gt; fun ; 
    int ff;
    while(!endFlag){

    if(!mySync.empty()){        
        bool result = mySync.pop(ff);
        if(result){
        fun = myGA.getIndex(ff);        
        fun();
        }
    }
    }
}


int main(int argc, char** argv){

    ThreadPool&lt;10&gt; tp;
    Functor ff(( [](){ cout &lt;&lt;"a kuku  "&lt;&lt;endl;  }));
    tp.bookTask(ff);
    std::this_thread::sleep_for(std::chrono::seconds(20));
    return 0 ; 
}
Just some stylistic things that stick out to me:


I think it's a bit cumbersome to have all of this:

using std::cout ; using std::cin; using std::endl;
using std::mutex; using std::atomic;
using std::array; using std::function;


You're also still prefixing std:: in places, which defeats the purpose of having this.  Since you could always end up using something not already in this list, you might as well keep prefixing std:: as you're doing already, and remove all of that above.
Some of your indentation and semicolon placing are inconsistent.  In some places you indent or not, and in some places you have a space before the ending semicolon.  Keep the indentation consistent (you should utilize it) and choose what to do with all of your semicolons.
It would be more readable and maintainable to place the template statements on separate lines from the class or function, especially if either statement is lengthy:

template &lt;typename T&gt;
class Class
{
};




template &lt;typename T&gt;
void function()
{
}