MySQL embedded and pthreads

Maximilian Kossick maximilian.kossick at googlemail.com
Tue Jul 29 09:49:54 CEST 2008


On Tue, Jul 29, 2008 at 8:32 AM, Edward Hades <edward.hades at gmail.com> wrote:
> On Tue, Jul 29, 2008 at 7:39 AM, Ian Monroe <ian at monroe.nu> wrote:
>> On Mon, Jul 28, 2008 at 3:17 PM, Edward Hades <edward.hades at gmail.com>
>> wrote:
>>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Hi, guys!
>>>
>>> As you possibly know, I've been working on MySQLe integration with
>>> Amarok. I have encountered several issues.
>>>
>>> First, MySQLe needs patching.
>>
>> That isn't really acceptable. We need to be able to depend on the distro
>> provided packages.
>>
> True, but it's build-only dependency. And if the two latter issues
> (key length and exit) are bearable, I am not quite sure if non-fPIC
> code can be used in shared libraries on every platform we target.
>
>>>
>>> I'll make a build script to simplify life for us, but
>>> packaging questions will remain (luckily it's a build-dep only, so this
>>> is not hard to settle).
>>
>> Why is it a build-only dep? Maybe I'm misunderstanding something.
> It's a static library (libmysqld.a).
>
>>
>>> Also, there is a thread safety issue. MySQL requires every thread to
>>> invoke certain procedures (mysql_thread_init and mysql_thread_end)
>>> before accessing its data and before death respectively. I've done some
>>> street pthread magic that takes care of initialization, but I still
>>> didn't come up with a way to run mysql_thread_end before thread exit.
>>
>> Yea pthread isn't portable and shouldn't be used directly really.
>>
>> Just an off-my-top, didn't-look-at-code idea:
>> You could use QThread::currentThread() to see if the current thread has been
>> initialized or not, and do so in the sqlcollection itself if it needs to be.
>>
>> That doesn't solve the uninitialized issue...
>>
>> Seems like the only solution is to explictly call the mysqle uninitalize
>> code when the thread is being deleted. This might not be that hard, its
>> quite possible only the sqlcollection's querybuilders threads access it
>> (outside of the gui thread).
>>
> Thanks, I'll look into it.

After thinking about it some more, the best solution is to use
QThreadStorage (which deletes the stored object when the thread exits,
so store some object which calls the mysql cleanup code in its dtor).
Qt is awesome:) that way ThreadWeaver can manage its thread pool and
Qt will take care of calling our cleanup code


More information about the Amarok-devel mailing list