当前位置:首页>Linux>Linux多线程编程(二):互斥锁与条件变量,手写生产者消费者模型

Linux多线程编程(二):互斥锁与条件变量,手写生产者消费者模型

  • 2026-07-02 16:45:56
Linux多线程编程(二):互斥锁与条件变量,手写生产者消费者模型

文章目录

  • 1、互斥问题
    • 1.1、抢票问题
    • 1.2、原因分析
  • 2、互斥锁
    • 2.1、互斥锁接口
    • 2.2、互斥锁实现原理
      • 2.2.1、硬件实现
      • 2.2.2、软件实现
    • 3.3、加锁的问题与原则
    • 2.3、封装互斥锁
  • 3、同步与条件变量
    • 3.1、同步与条件变量的概念
    • 3.2、条件变量接口
    • 3.3、封装条件变量
  • 4、生产者消费者模型
    • 4.1、原理
    • 4.2、单生产者单消费者实现
  • 5、总结

1、互斥问题

1.1、抢票问题

写一个模拟多线程抢票的代码:

CC=g++CFLAGS=-gLDFLAGS=-lpthreadOBJS=Main.o #Thread.ocode: $(OBJS)	$(CC) $(CFLAGS) -o $@ (LDFLAGS).PHONY: cleanclean:	rm -rf code *.o

Main.cpp

#include<pthread.h>#include<unistd.h>#include<stdio.h>#include<string>int ticket = 10000;voidBuyTicket(void* arg){    std::string* name = static_cast<std::string*>(arg);    while(true)    {        if(ticket > 0)        {            usleep(1000);            printf("%s: %d\n", name->c_str(), ticket);            ticket--;        }        else        {            break;        }    }    pthread_exit(nullptr);}intmain(){    pthread_t tid1, tid2, tid3, tid4;    std::string name1 = "tid1";    std::string name2 = "tid2";    std::string name3 = "tid3";    std::string name4 = "tid4";    pthread_create(&tid1, nullptr, BuyTicket, &name1);    pthread_create(&tid2, nullptr, BuyTicket, &name2);    pthread_create(&tid3, nullptr, BuyTicket, &name3);    pthread_create(&tid4, nullptr, BuyTicket, &name4);    pthread_join(tid1, nullptr);    pthread_join(tid2, nullptr);    pthread_join(tid3, nullptr);    pthread_join(tid4, nullptr);    return 0;}

有10000张票,四个线程模拟抢票,最终票数会到负数:

1.2、原因分析

原因1:在if(ticket > 0)这个语句非原子性,分为两步:从内存读取ticket到寄存器,ticket与0比较。在判断后,执行ticket--之前,线程可能被调取切换,当再次调度当前线程,ticket已经到0了,可是还会执行ticket--

原因2:ticket--非原子性操作,分为三步:从内存加载ticket变量到cpu寄存器,寄存器内容减一,保存到内存中。当执行到一半线程被切走,OS会保存硬件上下文,当再次被调度时,加载上下文,线程看到的ticket是旧的,导致数据被覆盖。

原因3:usleep(1000)模拟抢票行为,该函数为会阻塞线程,主动让出CPU。usleep、printf等函数会增加线程切换可能性。时钟中断也可能出现在if(ticket > 0)判断与ticket--之间。

注:判断某操作是否原子性最暴力的做法是查看汇编是否一行。

2、互斥锁

互斥锁的思想:任何时刻都只允许一个线程执行临界区代码。其它线程到没有拿到锁,会被阻塞。

2.1、互斥锁接口

互斥锁的类型是:pthread_mutex_t 动态初始化锁:

intpthread_mutex_init(pthread_mutex_t *mutex, constpthread_mutexattr_t *mutexattr);

参数:

  • mutex:需要初始化的锁。
  • mutexattr:初始化锁的属性,大多数情况直接填空指针,使用默认属性即可。

静态初始化锁:

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

PTHREAD_MUTEX_INITIALIZER是一个宏,pthread_mutex_init第二个参数传递空指针则属性等于这个宏。

静态初始化的宏是一个常量,锁存储在静态区,编译时确定大小,不需要手动销毁。常用于全局变量锁,静态变量锁。

动态初始化锁是栈上一个变量,运行时确定大小,需要手动销毁。

锁的销毁:

intpthread_mutex_destroy(pthread_mutex_t *mutex);

返回值:成功返回0。失败返回EBUSY,当线程持有锁时该函数执行失败。


加锁:

intpthread_mutex_lock(pthread_mutex_t *mutex);

返回值:成功返回0。当锁没有初始化好旧加锁失败返回EINVAL,当已经加锁再次加锁失败返回EDEADLK

尝试加锁:

intpthread_mutex_trylock(pthread_mutex_t *mutex);

返回值:成功返回0。锁被占用失败返回EBUSY,锁没有初始化失败返回EINVAL

与直接加锁的区别在于能加就加,不能加旧算了。直接加锁时,锁被别线程占用会阻塞。

解锁:

intpthread_mutex_unlock(pthread_mutex_t *mutex);

返回值:成功返回0。锁没有初始化失败返回EINVAL,不是自己加的锁没权限解锁返回EPERM

2.2、互斥锁实现原理

2.2.1、硬件实现

硬件实现非常简单,在加锁时。禁用时钟中断等线程调度行为。直到解锁重新打开这些功能。

硬件实现极其危险,若忘记写解锁代码或解锁失败,则操作系统直接卡死。

因此现代操作系统都是采用软件实现。

2.2.2、软件实现

大多数CPU架构指令集都提供了类似于swap/exchange这样的指令,这个指令是原子性的。

加锁伪代码:

lock:	movb 1, mutex	return 0

解锁过程就是将1写入内存mutex变量。

锁是否空闲看的事内存mutex是否为1。若为1,则说明锁没有被拿走,若为0,则说明锁被某线程拿到。

3.3、加锁的问题与原则

对于抢票代码的解决:

// 全局锁pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;voidBuyTicket(void* arg){    std::string* name = static_cast<std::string*>(arg);    while(true)    {        pthread_mutex_lock(&mutex); // 加锁        if(ticket > 0)        {            usleep(1000);            printf("%s: %d\n", name->c_str(), ticket);            ticket--;            pthread_mutex_unlock(&mutex); // 解锁        }        else        {            pthread_mutex_unlock(&mutex); // 解锁            break;        }    }    pthread_exit(nullptr);}

效果: 加锁后的临界区代码时串行执行的,因此会降低效率,所以要保证临界区尽量小,加锁粒度尽量细。

互斥锁本身也是共享资源,互斥锁的安全底层是swap/exchange保证的。

2.3、封装互斥锁

本节源码已经上传至gitee【https://gitee.com/muyi-2580/learning-linux/tree/main/5_24】。

以下源码用C++封装一个pthread库中的互斥锁,然后使用一个类继续封装成RAII风格,使其生命周期结束后自动解锁。

Mutex.cc:

#ifndef __MUTEX_H#define __MUTEX_H#include<pthread.h>class Mutex{private:    pthread_mutex_t mutex;public:    Mutex()     {        pthread_mutex_init(&mutex , nullptr);    }    ~Mutex()    {        pthread_mutex_destroy(&mutex);    }    voidLock()    {        pthread_mutex_lock(&mutex);    }    voidunLock()    {        pthread_mutex_unlock(&mutex);    }};// RAII风格封装class MutexGuard{private:    Mutex& mutex;public:    MutexGuard(Mutex& mutex)        :mutex(mutex) // 引用类型只能在初始化列表初始化    {        mutex.Lock();     }    ~MutexGuard()    {        mutex.unLock();    }};#endif

Main.cc

#include<pthread.h>#include<unistd.h>#include<string>#include"Mutex.cc"int ticket = 10000;// 全局锁Mutex mutex;voidBuyTicket(void* arg){    std::string* name = static_cast<std::string*>(arg);    while(true)    {        { // 临界区代码// 加锁, RAII风格	        MutexGuard mg(mutex);	        if(ticket > 0)	        {	            usleep(1000);	            printf("%s: %d\n", name->c_str(), ticket);	            ticket--;	        }	        else	        {	            break;	        }        }    }    pthread_exit(nullptr);}intmain(){    pthread_t tid1, tid2, tid3, tid4;    std::string name1 = "tid1";    std::string name2 = "tid2";    std::string name3 = "tid3";    std::string name4 = "tid4";    pthread_create(&tid1, nullptr, BuyTicket, &name1);    pthread_create(&tid2, nullptr, BuyTicket, &name2);    pthread_create(&tid3, nullptr, BuyTicket, &name3);    pthread_create(&tid4, nullptr, BuyTicket, &name4);    pthread_join(tid1, nullptr);    pthread_join(tid2, nullptr);    pthread_join(tid3, nullptr);    pthread_join(tid4, nullptr);    return 0;}

构造一个作用域可以提高代码可读性,一眼就能看出临界区。

3、同步与条件变量

3.1、同步与条件变量的概念

现有A、B、C三个线程竞争同一互斥锁(获得锁的线程执行相关任务)。开始A获得锁,执行完任务释放锁,A再次获得锁,执行完任务释放锁,A又获得锁……。B、C线程一直处于阻塞状态(阻塞状态也会被CPU调度),B、C无法完成自己的任务,且浪费CPU资源,这种情况叫做线程饥饿问题。

同步是只多个执行流协同执行的顺序。用人话说就是执行流访问资源按照某总顺序。同步常用条件变量实现。

pthread库提供了条件变量,条件变量在满足了某个条件时才继续执行。

条件变量底层原理是由一种唤醒机制和一个阻塞队列。当收到了其他线程的通知才能由阻塞到继续执行。在使用时一个唤醒 条件应该对应一个条件变量。

3.2、条件变量接口

条件变量是一个结构体,其类型是:pthread_cond_t  动态初始化条件变量:

intpthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr);

参数:

  • cond:需要初始化的条件变量。
  • cond_attr:初始化条件变量的属性,大多数情况下传空指针,使用默认属性。

静态初始化条件变量:

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

动态初始化的需要手动销毁,静态初始化的不需要手动销毁。原因与互斥锁类似。

销毁条件变量:

intpthread_cond_destroy(pthread_cond_t *cond);

返回值:成功返回0。当还有线程在等待条件变量时失败返回EBUSY


阻塞等待条件变量:

intpthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);

当前线程进入阻塞(依然能被调度),等待条件变量的唤醒后再执行。

该函数需要传递锁是因为在该函数内部会释放锁,让其他线程获得资源。


唤醒一个指定的条件变量:

intpthread_cond_signal(pthread_cond_t *cond);

会唤醒一个由该条件变量阻塞的线程,具体是哪一个就不确定了。

唤醒所有指定的条件变量:

intpthread_cond_broadcast(pthread_cond_t *cond);

3.3、封装条件变量

做一个简单封装 ,4.2节会用到。

#ifndef __CONDITION_CC#define __CONDITION_CC#include<pthread.h>class Cond{public:    Cond()    {        pthread_cond_init(&_cond, nullptr);    }    ~Cond()    {        pthread_cond_destroy(&_cond);    }    voidWait(pthread_mutex_t& mutex)    {        pthread_cond_wait(&_cond, &mutex);    }    voidSignal()    {        pthread_cond_signal(&_cond);    }private:    pthread_cond_t _cond;};#endif

4、生产者消费者模型

4.1、原理

生产者消费者模型(Producer-Consumer模型)是一种多线程的经典模型。

这个模型中有:

  • 三种关系:生产者-生产者,生产者-消费者,消费者-消费者。
  • 两种角色:生产者,消费者。
  • 一种交易场所:共享容器。

这个模型中,生产者不断生产商品,消费者不断消费商品。交易场所能容纳的商品有限。当商品满了(或者达到指定数量,或者达到容量的百分之九十),就不能继续生产了。当没有商品就不能继续消费了。

如果使用线程模拟生产者、消费者,三种关系:

  • 生产者-生产者:互斥。
  • 消费者-消费者:互斥。
  • 生产者-消费者:互斥/同步。

这个模型的优势在于:1、生产者与消费者线程解耦。2、生产过程可以与消费过程并发进行,提高效率。

在《管道通信深度剖析:从匿名管道到命名管道,手写进程池》中的进程池也是一个生产者消费者模型。父进程扮演生产者,子进程扮演消费者,管道扮演交易场所。

4.2、单生产者单消费者实现

本节代码依赖【https://gitee.com/muyi-2580/learning-linux/blob/main/5_18/thread.cc】。

本节源码已上传至gitee:【https://gitee.com/muyi-2580/learning-linux/tree/main/5_25】。

Main.cc:

#include"Mutex.cc"#include"Thread.cc"#include"BlockingQueue.cc"#include<iostream>#include<unistd.h>int num = 1;BlockingQueue<int> bq;voidProducerRoutine(){    while(1)    {        std::cout << "produce: " << num << std::endl;        bq.Enqueue(num);        num++;         // 生产得慢        usleep(100000);    }    pthread_exit(nullptr);}voidConsumerRoutine(){    while(1)    {        int data = 0;        bq.Pop(&data);        std::cout << "consume: " << data << std::endl;        // 消费得快        usleep(1000);    }    pthread_exit(nullptr);}intmain(){    ThreadModule::Thread c(ConsumerRoutine);    ThreadModule::Thread p(ProducerRoutine);    c.start();    p.start();    c.join();    p.join();    return 0;}

BlockingQueue.cc:

#ifndef __BLOCKING_QUEUE_CC#define __BLOCKING_QUEUE_CC#include"Condition.cc"#include<queue>#include"Mutex.cc"template<class T>class BlockingQueue{public:    BlockingQueue(int cap = 5)        :_capacity(cap)    {  }    ~BlockingQueue()    {  }    voidEnqueue(T& in)// 生产者,数据入队列    {        {            _mutex.Lock();            while(_que.size() == _capacity)            {                // 满了生产者等待                _ProducerCond.Wait(_mutex.getMutex());            }            // 数据入队            _que.push(in);            // 通知消费者消费            if(_que.size() == _capacity)                _ConsumerCond.Signal();            _mutex.unLock();        }    }    voidPop(T* out)// 消费者,数据出队列    {        {            _mutex.Lock();            if(_que.empty())            {                // 没有数据,消费者等待                _ConsumerCond.Wait(_mutex.getMutex());            }            // 消费(获取)数据            *out = _que.front();            _que.pop();            // 如果队空,通知生产者生产            if(_que.empty())                _ProducerCond.Signal();            _mutex.unLock();        }    }private:    Cond _ConsumerCond;    Cond _ProducerCond;    int _capacity;    std::queue<T> _que;    Mutex _mutex;};#endif

结果: 如上图,生产者生产5个(5个数据阻塞队列满)后就会通知消费至进行消费。

5、总结

1. 互斥问题与原因分析

  • 问题现象:多线程并发访问共享资源(如抢票)时,会出现数据不一致(票数为负)的问题。
  • 根本原因: 
    1. 判断非原子性:if(ticket > 0) 判断与后续操作之间可能被线程切换打断。
    2. 操作非原子性:ticket-- 等操作在汇编层面是多条指令,执行中途可能被中断。
    3. 函数调用引发切换:usleepprintf 等函数会增加线程切换概率。

2. 互斥锁(Mutex)解决方案

  • 核心思想:通过锁机制保证同一时刻只有一个线程进入临界区。
  • 接口使用: 
    • 动态初始化:pthread_mutex_init
    • 静态初始化:PTHREAD_MUTEX_INITIALIZER
    • 加锁/解锁:pthread_mutex_lock/pthread_mutex_unlock
  • 实现原理: 
    • 硬件实现(禁用中断)风险高,现代系统采用软件实现。
    • 基于原子指令(如 xchgb)实现锁的获取与释放。
  • 封装实践:使用 C++ RAII 风格封装 Mutex 和 MutexGuard 类,实现自动加锁解锁。

3. 同步与条件变量

  • 同步概念:协调多个执行流访问资源的顺序,解决线程饥饿问题。
  • 条件变量接口: 
    • 初始化:pthread_cond_init / PTHREAD_COND_INITIALIZER
    • 等待:pthread_cond_wait(会自动释放锁)
    • 唤醒:pthread_cond_signal(单个) / pthread_cond_broadcast(全部)
  • 封装实现:简单封装 Cond 类,便于后续使用。

4. 生产者-消费者模型

  • 模型组成: 
    • 三种关系:生产者-生产者(互斥)、消费者-消费者(互斥)、生产者-消费者(互斥+同步)
    • 两种角色:生产者、消费者
    • 一个交易场所:共享容器(如阻塞队列)
  • 优势:解耦生产与消费过程,支持并发执行,提高系统效率。
  • 单生产者单消费者实现: 
    • 使用阻塞队列作为共享容器
    • 队列满时生产者等待,队列空时消费者等待
    • 通过条件变量实现线程间的同步通知

5. 关键编程原则

  1. 临界区最小化:加锁范围应尽可能小,减少串行化带来的性能损失。
  2. 锁的安全使用:互斥锁本身也是共享资源,其安全性由底层原子指令保证。
  3. RAII 资源管理:通过对象的生命周期自动管理锁的获取与释放,避免忘记解锁。
  4. 条件变量配合互斥锁:条件变量等待时会自动释放锁,唤醒后重新获取锁。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 09:32:51 HTTP/2.0 GET : https://f.mffb.com.cn/a/495456.html
  2. 运行时间 : 0.227476s [ 吞吐率:4.40req/s ] 内存消耗:4,802.23kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=cdf2536728db9618eae6761d68e03834
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000418s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000599s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.005107s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.001453s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000719s ]
  6. SELECT * FROM `set` [ RunTime:0.028857s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000854s ]
  8. SELECT * FROM `article` WHERE `id` = 495456 LIMIT 1 [ RunTime:0.011538s ]
  9. UPDATE `article` SET `lasttime` = 1783042371 WHERE `id` = 495456 [ RunTime:0.032076s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.001696s ]
  11. SELECT * FROM `article` WHERE `id` < 495456 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.002918s ]
  12. SELECT * FROM `article` WHERE `id` > 495456 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.014037s ]
  13. SELECT * FROM `article` WHERE `id` < 495456 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.019494s ]
  14. SELECT * FROM `article` WHERE `id` < 495456 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.028915s ]
  15. SELECT * FROM `article` WHERE `id` < 495456 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.006688s ]
0.229056s