Boost logo

Boost Users :

Subject: [Boost-users] [interprocess]/[thread] - named_recursive_mutex spurious wake using scoped_lock
From: Daniel Biagini (daniel.biagini_at_[hidden])
Date: 2010-12-07 17:25:43


I'm running boost 1.43 on linux and seeing an issue where the scoped_lock<named_recursive_mutex> timed lock is returning immediately when another thread holds the lock.    The lock is being stored in shared memory

Am I doing something wrong?  The code in question is the azLog function below, (I included some other relevant snips as well).

thanks!
Dan

#define LOCK_WAIT_TIME 5; //seconds
static named_recursive_mutex *globalLock = create_logger_lock();

static named_recursive_mutex *create_logger_lock () {
    named_recursive_mutex *ptr = NULL;

    if (globalLock) {
        return(globalLock);
    }

    deadlock_count = 0;
    lock_timeout   = LOCK_WAIT_TIME;

    try {
        ptr = new named_recursive_mutex(open_or_create,
                                        (getShareName() + GLOBAL_LOCK).c_str());
    } catch (const interprocess_exception &ie) {
        cerr << "FATAL: Couldn't initialize the logging subsytem, IE err:" <<
                ie.what() << endl;
        throw;
    } catch (const std::exception &se) {
        cerr << "FATAL: Couldn't initialize the logging subsytem, std err:" <<
                se.what() << endl;
        throw;
    }
    return(ptr);
}

void azLog(AZ_LOG_SEVERITY sev, AZ_LOG_COMPONENT comp, const string& log_str) {
    ptime to = second_clock::local_time() + seconds(lock_timeout);
    scoped_lock<named_recursive_mutex> lock(*globalLock, to);

    while(!lock.owns() && (second_clock::local_time() < to)) {
        cerr << pthread_self() << ": SPURIOUS WAKE!!" << to_simple_string(second_clock::local_time()) << " <=:=> " << to_simple_string(to) << endl;
        lock.timed_lock(to);
    }
.....


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net