您现在的位置:主页 > 技术中心 > 数据库技术 > Mysql

Mysql源码学习——Connection Manager(4)

来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:54 点击:

 

线程数中,one_thread_scheduler和one_thread_per_connection_scheduler中设置的一个参数。这两者的区别便是是否创建了

 

一个新的线程来处理到来的连接。one_thread_scheduler是单线程方式,木有新建线程。我们重点研究one_thread_per_connection_scheduler,其设置的add_connection函数为create_thread_to_handle_connection:

 

create_thread_to_handle_connection(THD *thd)

{

    thread_created++;

    threads.append(thd); // 创建线程数自增,并加入到threads链表上

    pthread_create(&thd->real_id,&connection_attrib,

                              handle_one_connection,

                              (void*) thd);//这就是真正创建线程的地方了,函数便是handle_one_connection

}

 

  

 

    可见,最后调用了pthread_create函数,这个函数便是创建一个新的线程,新线程的处理函数为handle_one_connection.

 

5.新线程处理流程

 

     新线程处理函数为handle_one_connection,到此位置,一个新的connection被一个新创建的线程所单独处理。我们看下其中

 

是如何进行处理的。

 

handle_one_connection(void *arg)

{

    for (;;)

    {

        lex_start(thd); //初始化词法分析结构体

        login_connection(thd); //用户认证,失败报错

        prepare_new_connection_state(THD* thd);//Initialize THD to handle queries

         while (!net->error && net->vio != 0 &&   //循环处理command

           !(thd->killed == THD::KILL_CONNECTION))

        {

            if (do_command(thd))

              break;                   //处理失败跳出

          }

          end_connection(thd);         //关闭连接

          close_connection(thd, 0, 1);

         thread_scheduler.end_thread(thd,1);//结束线程

                  return 0;

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Tool
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql安装笔记
  • Mysql主主复制架构配置
  • Mysql的Procedure 参数为NULL问题分析
  • MySQL Stmt预处理提高效率问题的小研究
?? - ?? - ÝřŝžľŘÝź - TAGąęÇŠ - RSSśŠÔÄ - ??
Copyright © 2004-2024 上海卓卓网络科技有限公司