Fwd: Unusual behaviour of taglib using threads.

Sergey Vlasov vsu at altlinux.ru
Tue May 1 20:03:44 CEST 2007


On Tue, May 01, 2007 at 09:51:44PM +0530, Yogesh M wrote:
> If TagLib is not threadsafe, then my application is going to have
> *complete* design change (means hardwork of more than 1 yr becomes
> zero).

Unfortunately, TagLib does not seem to be threadsafe.  The worst
offender is the RefCounter class, which is used as a base for other
classes (e.g., ByteVector::ByteVectorPrivate):

  class RefCounter
  {
  public:
    RefCounter() : refCount(1) {}
    void ref() { refCount++; }
    bool deref() { return ! --refCount ; }
    int count() { return refCount; }
  private:
    uint refCount;
  };

Such implementation of ref() and deref() methods may give bogus result
if these methods are used concurrently by several threads - and this
will happen at least with ByteVector::null.  One of your crashes is in
ByteVector methods, another is in TagLib::String, which also uses
RefCounter - so probably this is the real problem.

There are other fishy places, but they seem to be mostly in the init
code (however, ID3v1::genreList() and ID3v1::genreMap() try to perform
initialization at the first call, which is not safe).  In general, any
global or static variable may give troubles unless the access to it is
appropriately protected.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.kde.org/pipermail/taglib-devel/attachments/20070501/04df1b3a/attachment.pgp 


More information about the taglib-devel mailing list