Re: [gmime-devel] thread safety and g_mime_init()



Title: thread safety and g_mime_init()
On 10/21/2011 12:17 PM, Junping Zhang wrote:

Hi, there,

  In my code, I call g_mime_init() at the start of the process, and then spawn multiple threads to do the parsing with code like this

    fd = open(...)

    gm_stream = g_mime_stream_fs_new(fd);
    gm_parser = g_mime_parser_new_with_stream(gm_stream);
    g_object_unref(gm_stream);

    gm_msg = g_mime_parser_construct_message(gm_parser);
    g_object_unref(gm_parser);

  Once in a while I got
    (process:2547): GLib-GObject-WARNING **: cannot register existing type `GMimeFilterBasic'

  I realized that there is a race condition in g_mime_stream_fs_get_type() which is called from g_mime_stream_fs_new(). If both threads got there at the same time and both got type 0, we would get the above warning. I believe this part of the code is the same in 2.4 through current 2.6.


Yes, it likely is. And you are right about what is happening.


  I thought g_mime_init() should initialize this type by calling g_mime_stream_fs_get_type() as it does for some other types, and I wonder what is the reason not to include some of the types and what should be the recommended calling sequence here.


No reason but lazyness, I'm afraid. I'll fix this up for 2.4.27 and 2.6.1.

Jeff



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