且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在c ++中超时mysql ++查询

更新时间:2023-02-08 11:09:36

方式:

您在单独的线程上执行查询,无论是否发生超时都会继续运行。超时发生在主线程,并将变量设置为1,标记它发生。然后你做你想做的任何你的主线程。

You execute the query on a separate thread, that keeps running whether or not the timeout occurs. The timeout occurs on the main thread, and sets a variable to "1" marking that it occurred. Then you do whatever you want to do on your main thread.

查询线程在查询完成后会检查是否发生超时。如果没有,它做它需要做的其余工作。如果它已经存在,它只是解锁它刚刚锁定的表。

The query thread, once the query completes, checks if the timeout has occurred. If it hasn't, it does the rest of the work it needs to do. If it HAS, it just unlocks the tables it just locked.

我知道这听起来有点浪费,但锁定解锁时间应该基本上是瞬间的,你尽可能接近你想要的结果。

I know it sounds a bit wasteful, but the lock-unlock period should be basically instantaneous, and you get as close to the result you want as possible.