signal and unlock order

Viewed 10800
void WorkHandler::addWork(Work* w){
    printf("WorkHandler::insertWork Thread, insertWork locking \n");
    lock();
    printf("WorkHandler::insertWork Locked, and inserting into queue \n");
    m_workQueue.push(w);
    signal();
    unLock();
}

I followed a tutorial and I got this. I was wondering if it is ok to change the order of singal() and unLock() like this

void WorkHandler::addWork(Work* w){
    printf("WorkHandler::insertWork Thread, insertWork locking \n");
    lock();
    printf("WorkHandler::insertWork Locked, and inserting into queue \n");
    m_workQueue.push(w);
    unLock();
    signal();
}

If I can't do this, could you please give me details why I am not allowed to do this? Thanks in advance.

3 Answers
Related