Re: [sigc] Re: [gtkmm] libsigcx and gtkmm 2.4



Am Mo, den 14.06.2004 um 1:18 Uhr +0200 schrieb Daniel Elstner:

> > But if fail to see how locking the mutex before creating the original 
> > string would make any difference. Successfully locking or unlocking a 
> > mutex is guaranteed to synchronize memory with respect to other threads 
> > regardless of whether that memory was touched before or after the mutex 
> > was locked.
> 
> That's new to me.  Do you have any reference on that?

Okay, you're (partly) right.  ("Partly" because it's not "locking or
unlocking": what's needed is unlock in thread A and lock in thread B.)
I found this in Butenhof:

        Whatever memory values a thread can see when it unlocks a mutex,
        either directly or by waiting on a condition variable, can also
        be seen by any thread that later locks the same mutex.  Again,
        data written after the mutex is unlocked may not necessarily be
        seen by the thread that locks the mutex, even if the write
        occurs before the lock.

In other words, the sequence

        pthread_mutex_lock(mutex);
        pthread_mutex_unlock(mutex);

issues a memory barrier instruction on the unlock.  The other thread
that wants to read the data still has to lock the same mutex though.

--Daniel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]