[vdr] Making a cList object thread safe?

Christian Wieninger cwieninger at gmx.de
Sun Aug 20 13:34:10 CEST 2006

> You have to protect all functions of your object which are
> dealing with the list (reading and/or writing) with a cMutex.
Thanks! So the following should work (please correct me if I'm wrong):
I add a cMutex object in the cList derived class and 2 functions:

class cThreadSafecList: public cList<...> {
    cMutex mutex;
    void Lock(void) { mutex.Lock(); }
    void Unlock(void) { mutex.Unlock(); }

extern cThreadSafecList MyThreadSafecList;

Every member function with access to the list objects calls Lock and 
Unlock at the beginning and end of the function.
Every direct access to the MyThreadSafecList object (to loop throug or 
manipulate the list objects) must make sure to call 
MyThreadSafecList.Lock and MyThreadSafecList.Unlock. The locking time 
should be short to avoid a sluggish OSD, if one accesses 
MyThreadSafecList in the main thread.



More information about the vdr mailing list