当前位置:首页>Linux>第11讲:linux下多线程编程实例

第11讲:linux下多线程编程实例

  • 2026-08-18 23:10:29
第11讲:linux下多线程编程实例

在Linux系统编程中,多线程编程是一项核心技能,它能够充分利用多核处理器的并行计算能力,显著提升程序的性能和响应速度。与多进程相比,线程间共享内存空间,通信更加高效,但也带来了数据竞争、死锁等并发问题。

POSIX线程(Pthreads)是Linux下最常用的多线程编程接口,它提供了一套完整的API来管理线程的生命周期、同步机制和线程间通信。掌握多线程编程不仅需要理解API的使用,更重要的是建立正确的并发编程思维,能够设计出既高效又安全的并发程序。

本文通过四个循序渐进的实例,从基础的线程创建和互斥锁使用,到经典的生产者-消费者模型,再到线程池的实现,最后介绍读写锁的应用,帮助大家全面掌握Linux多线程编程的关键技术。

1. 基础线程创建与同步

#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include<unistd.h>#define NUM_THREADS 5// 互斥锁保护共享资源pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;int shared_counter = 0;// 线程函数voidthread_function(void* arg){    int thread_id = *(int*)arg;    // 加锁保护临界区    pthread_mutex_lock(&mutex);    shared_counter++;    printf("Thread %d: counter = %d\n", thread_id, shared_counter);    pthread_mutex_unlock(&mutex);    // 模拟工作    sleep(1);    printf("Thread %d: finished\n", thread_id);    return NULL;}intmain(){    pthread_t threads[NUM_THREADS];    int thread_ids[NUM_THREADS];    // 创建线程    for (int i = 0; i < NUM_THREADS; i++) {        thread_ids[i] = i;        if (pthread_create(&threads[i], NULL, thread_function, &thread_ids[i]) != 0) {            perror("pthread_create");            exit(1);        }        printf("Main: created thread %d\n", i);    }    // 等待所有线程完成    for (int i = 0; i < NUM_THREADS; i++) {        pthread_join(threads[i], NULL);        printf("Main: thread %d joined\n", i);    }    pthread_mutex_destroy(&mutex);    printf("Final counter: %d\n", shared_counter);    return 0;}

编译命令:

gcc -o thread_basic thread_basic.c -pthread

2. 生产者-消费者模型

#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include<unistd.h>#define BUFFER_SIZE 10#define NUM_PRODUCERS 3#define NUM_CONSUMERS 2#define ITEMS_PER_PRODUCER 5// 缓冲区结构typedef struct {    int buffer[BUFFER_SIZE];    int in;    int out;    int count;    pthread_mutex_t mutex;    pthread_cond_t not_full;    pthread_cond_t not_empty;} Buffer;Buffer shared_buffer = {    .in = 0,    .out = 0,    .count = 0,    .mutex = PTHREAD_MUTEX_INITIALIZER,    .not_full = PTHREAD_COND_INITIALIZER,    .not_empty = PTHREAD_COND_INITIALIZER};// 生产者线程voidproducer(void* arg){    int producer_id = *(int*)arg;    for (int i = 0; i < ITEMS_PER_PRODUCER; i++) {        pthread_mutex_lock(&shared_buffer.mutex);        // 等待缓冲区非满        while (shared_buffer.count == BUFFER_SIZE) {            pthread_cond_wait(&shared_buffer.not_full, &shared_buffer.mutex);        }        // 生产数据        int item = producer_id * 100 + i;        shared_buffer.buffer[shared_buffer.in] = item;        shared_buffer.in = (shared_buffer.in + 1) % BUFFER_SIZE;        shared_buffer.count++;        printf("Producer %d: produced item %d (buffer: %d/%d)\n"               producer_id, item, shared_buffer.count, BUFFER_SIZE);        // 通知消费者        pthread_cond_signal(&shared_buffer.not_empty);        pthread_mutex_unlock(&shared_buffer.mutex);        usleep(rand() % 500000);  // 随机延迟    }    return NULL;}// 消费者线程voidconsumer(void* arg){    int consumer_id = *(int*)arg;    while (1) {        pthread_mutex_lock(&shared_buffer.mutex);        // 等待缓冲区非空        while (shared_buffer.count == 0) {            pthread_cond_wait(&shared_buffer.not_empty, &shared_buffer.mutex);        }        // 消费数据        int item = shared_buffer.buffer[shared_buffer.out];        shared_buffer.out = (shared_buffer.out + 1) % BUFFER_SIZE;        shared_buffer.count--;        printf("Consumer %d: consumed item %d (buffer: %d/%d)\n"               consumer_id, item, shared_buffer.count, BUFFER_SIZE);        // 通知生产者        pthread_cond_signal(&shared_buffer.not_full);        pthread_mutex_unlock(&shared_buffer.mutex);        usleep(rand() % 800000);  // 随机延迟    }    return NULL;}intmain(){    pthread_t producers[NUM_PRODUCERS];    pthread_t consumers[NUM_CONSUMERS];    int producer_ids[NUM_PRODUCERS];    int consumer_ids[NUM_CONSUMERS];    srand(time(NULL));    // 创建生产者线程    for (int i = 0; i < NUM_PRODUCERS; i++) {        producer_ids[i] = i + 1;        pthread_create(&producers[i], NULL, producer, &producer_ids[i]);    }    // 创建消费者线程    for (int i = 0; i < NUM_CONSUMERS; i++) {        consumer_ids[i] = i + 1;        pthread_create(&consumers[i], NULL, consumer, &consumer_ids[i]);    }    // 等待生产者完成    for (int i = 0; i < NUM_PRODUCERS; i++) {        pthread_join(producers[i], NULL);    }    // 等待缓冲区清空后取消消费者    sleep(2);    for (int i = 0; i < NUM_CONSUMERS; i++) {        pthread_cancel(consumers[i]);    }    printf("All producers finished\n");    return 0;}

3. 线程池实现

#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include<unistd.h>#define THREAD_POOL_SIZE 4#define TASK_QUEUE_SIZE 10// 任务结构typedef struct {    void (*function)(void*);    void* arg;} Task;// 线程池结构typedef struct {    Task task_queue[TASK_QUEUE_SIZE];    int queue_front;    int queue_rear;    int queue_count;    int active;    pthread_mutex_t mutex;    pthread_cond_t not_empty;    pthread_cond_t not_full;    pthread_t threads[THREAD_POOL_SIZE];} ThreadPool;ThreadPool pool = {    .queue_front = 0,    .queue_rear = 0,    .queue_count = 0,    .active = 1,    .mutex = PTHREAD_MUTEX_INITIALIZER,    .not_empty = PTHREAD_COND_INITIALIZER,    .not_full = PTHREAD_COND_INITIALIZER};// 示例任务函数voidsample_task(void* arg){    int task_id = *(int*)arg;    printf("Thread %lu: executing task %d\n"pthread_self(), task_id);    sleep(1);  // 模拟工作    printf("Thread %lu: completed task %d\n"pthread_self(), task_id);}// 工作线程函数voidworker_thread(void* arg){    while (1) {        pthread_mutex_lock(&pool.mutex);        // 等待任务        while (pool.queue_count == 0 && pool.active) {            pthread_cond_wait(&pool.not_empty, &pool.mutex);        }        if (!pool.active && pool.queue_count == 0) {            pthread_mutex_unlock(&pool.mutex);            break;        }        // 获取任务        Task task = pool.task_queue[pool.queue_front];        pool.queue_front = (pool.queue_front + 1) % TASK_QUEUE_SIZE;        pool.queue_count--;        pthread_cond_signal(&pool.not_full);        pthread_mutex_unlock(&pool.mutex);        // 执行任务        task.function(task.arg);    }    return NULL;}// 提交任务到线程池voidsubmit_task(void (*function)(void*), void* arg){    pthread_mutex_lock(&pool.mutex);    while (pool.queue_count == TASK_QUEUE_SIZE) {        pthread_cond_wait(&pool.not_full, &pool.mutex);    }    pool.task_queue[pool.queue_rear].function = function;    pool.task_queue[pool.queue_rear].arg = arg;    pool.queue_rear = (pool.queue_rear + 1) % TASK_QUEUE_SIZE;    pool.queue_count++;    pthread_cond_signal(&pool.not_empty);    pthread_mutex_unlock(&pool.mutex);}// 初始化线程池voidinit_thread_pool(){    for (int i = 0; i < THREAD_POOL_SIZE; i++) {        pthread_create(&pool.threads[i], NULL, worker_thread, NULL);    }}// 销毁线程池voiddestroy_thread_pool(){    pthread_mutex_lock(&pool.mutex);    pool.active = 0;    pthread_cond_broadcast(&pool.not_empty);    pthread_mutex_unlock(&pool.mutex);    for (int i = 0; i < THREAD_POOL_SIZE; i++) {        pthread_join(pool.threads[i], NULL);    }    pthread_mutex_destroy(&pool.mutex);    pthread_cond_destroy(&pool.not_empty);    pthread_cond_destroy(&pool.not_full);}intmain(){    printf("Starting thread pool with %d threads\n", THREAD_POOL_SIZE);    init_thread_pool();    // 提交15个任务    int task_ids[15];    for (int i = 0; i < 15; i++) {        task_ids[i] = i + 1;        submit_task(sample_task, &task_ids[i]);        printf("Submitted task %d\n", i + 1);    }    // 等待所有任务完成    sleep(5);    printf("Destroying thread pool\n");    destroy_thread_pool();    return 0;}

4. 读写锁示例

#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include<unistd.h>#define NUM_READERS 5#define NUM_WRITERS 2// 共享数据结构typedef struct {    int data;    int read_count;    pthread_mutex_t mutex;    pthread_cond_t can_write;    pthread_cond_t can_read;    int writing;} SharedData;SharedData shared = {    .data = 0,    .read_count = 0,    .mutex = PTHREAD_MUTEX_INITIALIZER,    .can_write = PTHREAD_COND_INITIALIZER,    .can_read = PTHREAD_COND_INITIALIZER,    .writing = 0};// 读者线程voidreader(void* arg){    int reader_id = *(int*)arg;    while (1) {        pthread_mutex_lock(&shared.mutex);        // 等待写者完成        while (shared.writing) {            pthread_cond_wait(&shared.can_read, &shared.mutex);        }        shared.read_count++;        pthread_mutex_unlock(&shared.mutex);        // 读操作        printf("Reader %d: read data = %d (readers: %d)\n"               reader_id, shared.data, shared.read_count);        pthread_mutex_lock(&shared.mutex);        shared.read_count--;        // 如果没有读者,通知写者        if (shared.read_count == 0) {            pthread_cond_signal(&shared.can_write);        }        pthread_mutex_unlock(&shared.mutex);        sleep(1);    }    return NULL;}// 写者线程voidwriter(void* arg){    int writer_id = *(int*)arg;    while (1) {        pthread_mutex_lock(&shared.mutex);        // 等待所有读者完成        while (shared.read_count > 0) {            pthread_cond_wait(&shared.can_write, &shared.mutex);        }        shared.writing = 1;        // 写操作        shared.data++;        printf("Writer %d: wrote data = %d\n", writer_id, shared.data);        shared.writing = 0;        // 通知等待的读者        pthread_cond_broadcast(&shared.can_read);        pthread_mutex_unlock(&shared.mutex);        sleep(2);    }    return NULL;}intmain(){    pthread_t readers[NUM_READERS];    pthread_t writers[NUM_WRITERS];    int reader_ids[NUM_READERS];    int writer_ids[NUM_WRITERS];    // 创建读者线程    for (int i = 0; i < NUM_READERS; i++) {        reader_ids[i] = i + 1;        pthread_create(&readers[i], NULL, reader, &reader_ids[i]);    }    // 创建写者线程    for (int i = 0; i < NUM_WRITERS; i++) {        writer_ids[i] = i + 1;        pthread_create(&writers[i], NULL, writer, &writer_ids[i]);    }    // 运行一段时间    sleep(10);    // 取消线程    for (int i = 0; i < NUM_READERS; i++) {        pthread_cancel(readers[i]);    }    for (int i = 0; i < NUM_WRITERS; i++) {        pthread_cancel(writers[i]);    }    return 0;}

编译和运行

所有示例都需要链接pthread库:

# 基础示例gcc -o thread_basic thread_basic.c -pthread./thread_basic# 生产者消费者gcc -o producer_consumer producer_consumer.c -pthread./producer_consumer# 线程池gcc -o thread_pool thread_pool.c -pthread./thread_pool# 读写锁gcc -o read_write read_write.c -pthread./read_write

通过以上四个实例,我们系统地学习了Linux下多线程编程的核心技术。从基础线程创建到复杂的线程池实现,每个示例都体现了并发编程中的重要概念:线程同步确保数据一致性,互斥锁保护临界区,条件变量实现线程间的协调通信,线程池则是实际项目中常用的性能优化手段。

在实际开发中,多线程编程还需要注意以下几点:

  • 避免死锁:设计锁的获取顺序,使用pthread_mutex_trylock()等非阻塞函数

  • 合理设置线程数量:过多线程会导致上下文切换开销,通常建议为CPU核心数的1-2倍

  • 使用线程局部存储__thread关键字或pthread_setspecific()避免不必要的锁竞争

  • 选择合适的同步机制:读写锁适合读多写少场景,信号量适合资源计数场景

  • 善用调试工具:Valgrind的Helgrind工具、gdb的线程调试功能都是排查并发问题的利器

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-08-22 01:20:36 HTTP/2.0 GET : https://f.mffb.com.cn/a/504467.html
  2. 运行时间 : 0.238182s [ 吞吐率:4.20req/s ] 内存消耗:4,575.02kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=8002de2c20835daf5c7ea507bb0d122d
  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.000718s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000655s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.008863s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000290s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000499s ]
  6. SELECT * FROM `set` [ RunTime:0.000218s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000558s ]
  8. SELECT * FROM `article` WHERE `id` = 504467 LIMIT 1 [ RunTime:0.015184s ]
  9. UPDATE `article` SET `lasttime` = 1787332836 WHERE `id` = 504467 [ RunTime:0.017549s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.000290s ]
  11. SELECT * FROM `article` WHERE `id` < 504467 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.013152s ]
  12. SELECT * FROM `article` WHERE `id` > 504467 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.005646s ]
  13. SELECT * FROM `article` WHERE `id` < 504467 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.022096s ]
  14. SELECT * FROM `article` WHERE `id` < 504467 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.000903s ]
  15. SELECT * FROM `article` WHERE `id` < 504467 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000622s ]
0.239872s