Thread safety for ID3v1 genres

Lukáš Lalinský lalinsky at
Mon May 2 20:58:27 CEST 2011

On Mon, May 2, 2011 at 1:27 PM, Stephen F. Booth <me at> wrote:
>>>     static const int genresSize = 148;
>>> -    static const String genres[] = {
>>> +    static const char * genres[] = {
>>>       "Blues",
>> This is actually one of those things that I've mentioned that if TagLib wants to be truly reentrant that the static initializers (which there are a fair number of) will need to be possible to invoke manually, mutexed or to go away.  While I doubt the initialization the problem there, the function is fundamentally not reentrant since there's a possible race condition on the first call to the function.
> I still would suggest the patch above, because no C++ objects are
> being created at static initialization time.

I have no problem with the patch, the cost of creating the genre
string objects is nothing compared to the rest of the tag parsing.

The problem is definitely solvable, but it's probably not worth it. We
could add a special flag that would say that the C version should be
generated together with constructing the string and that it's
immutable. String::toCString would then always return the same string.


More information about the taglib-devel mailing list