• 临界区 sleep


    24.1 Sleep

    In some cases race conditions can be repeated when all but one thread are blocked (for example waiting for an SQL lock). Then the remaining thread has plenty of time to go through the critical piece of code.

    The problem here is to assure that the blocking threads run until they reach their blocking point before the remaining thread reaches the critical code.

    One solution is to use the 'sleep' command of 'mysqltest' in front of the SQL statement that drives the remaining thread into the critical code.

    Example:

    --connection conn1
       LOCK TABLE t1 WRITE;
           --connection conn2
           # This will block in wait_for_lock().
           send INSERT INTO t1 VALUES (1);
       --connection conn1
       # Sleep until we can be sure that conn2 reached wait_for_lock().
       --sleep 2
       # Run through the critical code.
       FLUSH TABLE t1;

    The BIG, BIG problem with 'sleep' is that you need to specify a fixed time. It must be big enough so that the test works as intended even on a very slow machine that is under heavy load. Hence it is much too big for the average machine. A major waste of time.

    The bottom line is: AVOID 'SLEEP' WHEREVER POSSIBLE.

    MySQL :: MySQL Internals Manual :: 24.1 Sleep https://dev.mysql.com/doc/internals/en/sleep.html

  • 相关阅读:
    对字符串做预处理 、 工具类
    判断对象是否为空 、 工具类
    判断集合是否为空 、 工具类
    jquery取值
    时间年月日格式化
    图片上传
    验证码解决方案
    PHP高效率写法
    关于ip判断
    composer(管理依赖关系的工具) 及配置信息
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15475141.html
Copyright © 2020-2023  润新知