MySQL: Transactions across multiple threads

后端 未结 3 652
我寻月下人不归
我寻月下人不归 2021-01-12 07:39

Preliminary:

I have an application which maintains a thread pool of about 100 threads. Each thread can last about 1-30 seconds before a new task re

3条回答
  •  别那么骄傲
    2021-01-12 08:07

    Well, as stated in a different answer you can't create a transaction across multiple connections. And you can share the single connection across threads. However you need to be very careful with that. You need to make sure that only one thread is writing to the connection at the same time. You can't just have multiple threads talking across the same connection without synchronizing their activities in some way. Bad things will likely happen if you allow two threads to talk at once (memory corruptions in the client library, etc). Using a mutex or critical section to protect the connection conversations is probably the way to go.

    -Don

提交回复
热议问题