0

I'm using libmysql in a simple multithreaded app which will run on a uni-core embedded system processor. I read here that the client library is almost thread-safe.

Do I need to serialise my app (say, with a mutex)?

4

1 回答 1

3

取决于你在做什么。在一个简单的场景中,您只需链接libmysqlclient_r并确保您不会与多个线程共享连接,也不会在单个连接上“同时”执行多个查询。

其他需求:

  1. 在创建任何线程之前,调用mysql_library_init()初始化 MySQL 库;
  2. mysql_thread_init()在使用任何 MySQL 相关函数之前,在每个线程调用以初始化特定于线程的变量;
  3. 在销毁线程之前,调用mysql_thread_end().

如果您的程序遵守这些限制,那么 MySQL 就是您的朋友。

于 2014-11-14T18:40:58.297 回答