线程详解(接上篇博客)

目录

1.生产者消费者模型;

2.基于环形队列的生产者消费者模型;

3.线程池;

4.STL, 智能指针, 线程安全;

5.读者写者问题.


前言:

        本篇博客博主五一假期都在肝的一篇, 希望xdm点点三连, 博主感谢了 onz !!!

1.生产者消费者模型

321原则:(便于记忆)

3是指3种关系: 生产者和生产者; 消费者和消费者;生产者和消费者.

2是2种角色: 生产者和消费者;

1是指一个交易场所: 内存空间.

 1.1为什么要使用生产者消费者模型?

生产者和消费者模型是通过一个容器来解决生产者和消费者强解耦问题, 生产者和消费者通过阻塞队列进行通讯, 阻塞队列就相当于一个缓冲区, 消费者是从阻塞队列里面拿数据, 生产者生产的数据不用给消费者,直接给到阻塞队列里面, 这样可以平衡生产者和消费者的能力.(忙闲不均)

1.2生产者消费者模型的优点

(1)解耦; (2)支持并发; (3)支持忙闲不均.

 1.3基于阻塞队列的生产消费模型

阻塞队列当队列为空的时候, 消费者无法取数据而是被阻塞,直到生产新数据.当队列为满的时,生产者也不会再生产数据而是被阻塞, 直到消费数据.

1.4代码

这里封装四个模块进行编写.对每个模块进行详细解答.

首先的是BlockQueue.hpp, 封装一个阻塞队列.

条件变量_p_cond和_c_cond都是用来阻塞队列生产消费关系处理的.

#pragma once

#include<iostream>
#include<queue>
#include"LockGuard.hpp"
using namespace std;

const int defaultcap = 5;

template<class T>
class BlockQueue
{
public:
    BlockQueue(int cap = defaultcap)
        :_capacity(cap)
    {
        pthread_mutex_init(&_mutex, nullptr);
        pthread_cond_init(&_p_cond, nullptr);
        pthread_cond_init(&_c_cond, nullptr);
    }

    bool IsFull()
    {
        return _q.size() == _capacity;
    }

    bool IsEmpty()
    {
        return _q.size() == 0;
    }

    void Push(const T& in)//生产者生产数据
    {
        LockGuard lockguard(&_mutex);
        while(IsFull())
        {
            pthread_cond_wait(&_p_cond, &_mutex);
        }
       
       _q.push(in);
       pthread_cond_signal(&_c_cond);
    }

    void Pop(T* out)//消费者消费数据
    {
        LockGuard lockguard(&_mutex);
        while(IsEmpty())
        {
            pthread_cond_wait(&_c_cond, &_mutex);
        }

        *out = _q.front();
        _q.pop();
        pthread_cond_signal(&_p_cond);
    }

    ~BlockQueue()
    {
        pthread_mutex_destroy(&_mutex);
        pthread_cond_destroy(&_p_cond);
        pthread_cond_destroy(&_c_cond);
    }

private:
    queue<T> _q;
    int _capacity;
    pthread_mutex_t _mutex;
    pthread_cond_t _p_cond; //生产者的条件变量
    pthread_cond_t _c_cond; /* 消费者的条件变量 */
};

上面BlockQueue还需要封装了一个锁LockGuard; 

这里就是封装了一个互斥量(锁)

#pragma once

#include<pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t* lock)
        :_lock(lock)
    {}

    void Lock()
    {
        pthread_mutex_lock(_lock);
    }

    void unlock()
    {
        pthread_mutex_unlock(_lock);
    }

    ~ Mutex()
    {}
private:
    pthread_mutex_t* _lock;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* lock)
        :_mutex(lock)
    {
        _mutex.Lock();
    }

    ~LockGuard()
    {
        _mutex.unlock();
    }
private:
    Mutex _mutex;
};

生产者生产数据和消费者消费数据的数据, 这里我们Task.hpp来实现+-*/%的处理类.

#pragma once
#include<iostream>
#include<string>
#include<unistd.h>

using namespace std;

const int defaultvalue = 0;
const string opers = "+-*/%)(|";

enum
{
    ok = 0,
    div_zero,
    mod_zero,
    unkown
};

class Task
{
public:
    Task()
    {}
    
    Task(int x, int y, char op)
        :data_x(x)
        ,data_y(y)
        ,oper(op)
        ,result(defaultvalue)
        ,code(ok)
    {}

    void Run()
    {
        switch(oper)
        {
        case'+':
            result = data_x + data_y;
            break;
        case'-':
            result = data_x - data_y;
            break;
        case'*':
            result = data_x * data_y;
            break;
        case'/':
          {
            if(data_y == 0)
                code = div_zero;
            else
                result = data_x / data_y;
          }
        break;
        case'%':
          {
            if(data_y == 0)
                code = mod_zero;
            else
                result = data_x % data_y;
          }
        break;
        default:
            code = unkown;
            break;
        }
    }

    void operator()()
    {
        Run();
        sleep(2);
    }

    string PrintTask()
    {
        string s;
        s = to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += "=?";

        return s;
    }

    string PrintResult()
    {
        string s;
        s = to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += "=";
        s += to_string(result);
        s += "[";
        s += to_string(code);
        s += "]";

        return s;
    }

    ~Task()
    {}
private:
    int data_x;
    int data_y;
    char oper;  //+-/*%
    int result;
    int code;  /* 结果码 0: 可信, !0 不可信 */
};

最后一个main.cc进行测试;

这里p表示生产者, c表示消费者; ThreadData是封装了阻塞队列以及线程名称.

消费者对于数据是消费那么就是pop数据, 并且还要的到数据结果; 生产者是push数据, 并且还要更新数据的信息.

#include<iostream>
#include<pthread.h>
#include<time.h>
#include<unistd.h>
#include"Blockqueue.hpp"
#include"Task.hpp"
using namespace std;

class ThreadData
{
public:
    BlockQueue<Task>* bq;
    string name;
};

void* consumer(void* args)
{
    ThreadData* td = (ThreadData*)args;

    while(true)
    {
        Task t;
        td->bq->Pop(&t);

        t.Run();
        cout << "consumer data:" << t.PrintResult() << "," << td->name << endl; 
    }

    return nullptr;
}

void* productor(void* args)
{
    BlockQueue<Task>* bq = static_cast<BlockQueue<Task>*>(args);

    while(true)
    {
        int data1 = rand() % 10;
        usleep(rand()%123);

        int data2 = rand() % 10;
        usleep(rand()%123);

        char oper = opers[rand() % opers.size()];
        Task t(data1, data2, oper);

        cout << "productor task:" << t.PrintTask() << endl;
        bq->Push(t);
        sleep(1);
    }
    return nullptr;
}

int main()
{
    /* 形成随机数 */
    srand((uint16_t)time(nullptr) ^ getpid() ^ pthread_self());
    BlockQueue<Task>* bq = new BlockQueue<Task>();
    pthread_t c[3], p[2];/* consumer productor */

    ThreadData* td = new ThreadData();
    td->bq = bq;
    td->name = "thread-1";
    /* 消费者1 */
    pthread_create(&c[0], nullptr, consumer, td);

    ThreadData* td1 = new ThreadData();
    td1->bq = bq;
    td1->name = "thread-2";
    /* 消费者2 */
    pthread_create(&c[1], nullptr, consumer, td1);

    ThreadData* td2 = new ThreadData();
    td2->bq = bq;
    td2->name = "thread-3";
    /* 消费者3 */
    pthread_create(&c[2], nullptr, consumer, td2);

    pthread_create(&p[0], nullptr, productor, bq);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(c[2], nullptr);
    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);

    return 0;
}

2.基于环形队列的生产者消费者模型

先穿插讲一个日志, 如何写日志.

va_list: 宏定义, 是一个指向变长参数列表的指针.

va-start: 可变参数的起始地址, ap是参数va_list, last是最后固定参数的地址.

va_end: 结束使用变长参数列表, 用于清空va_list和va_start

#pragma once
#include<iostream>
#include<stdarg.h>
#include<time.h>
using namespace std;

enum
{
    Debug = 0,
    Info,
    warning,
    Error,
    Fatal
};


string LevelToString(int level)
{
    switch(level)
    {
        case Debug:
            return "Debug";
        case Info:
            return "Info";
        case warning:
            return "warning";
        case Error:
            return "Error";
        case Fatal:
            return "Fatal";
        default:
            return "unkown";
    }
}

class Log
{
public:
    Log(){}

    void LogMessage(int level, const char* format, ...)
    {
        char content[1024];
        va_list args;//可变参数
        va_start(args, format);
        vsnprintf(content, sizeof(content), format, args);
        va_end(args);
        uint64_t currtime = time(nullptr);
        printf("[%s][%s]%s\n", LevelToString(level).c_str(), 
                to_string(currtime).c_str(), content);
    }

    ~Log(){}
private:    
};

#include<iostream>
#include"Log.hpp"
#include"RingQueue.hpp"
#include"Task.hpp"
#include<pthread.h>
#include<ctime>
using namespace std;

void* Productor(void* args)
{
    RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(args);

    while(true)
    {
        int data1 = rand() % 10;
        usleep(rand() % 123);

        int data2 = rand() % 10;
        usleep(rand() % 123); 

        char oper = opers[rand() % (opers.size())];
        Task t(data1, data2, oper);
        cout << "productor task: " << t.PrintTask() << endl;

        rq->Push(t);
    }
    return nullptr;
}

void* consumer(void* args)
{
     RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(args);
     while(true)
     {
        Task t;
        rq->Pop(&t);

        t.Run();
        cout << "consumer done, data is : " << t.PrintResult() << endl;
     }
}

int main()
{
   /*  Log log;
    log.LogMessage(Debug, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(warning, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(Error, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(Info, "hello %d, %s, %f", 10, "study", 3.14);
     */
    

    srand((uint64_t)time(nullptr) ^ pthread_self());
    pthread_t c[3], p[2];

    RingQueue<Task>* rq = new RingQueue<Task>();

    pthread_create(&p[0], nullptr, Productor, rq);
    pthread_create(&p[1], nullptr, Productor, rq);

    pthread_create(&c[0], nullptr, consumer, rq);
    pthread_create(&c[1], nullptr, consumer, rq);
    pthread_create(&c[2], nullptr, consumer, rq);

    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(c[2], nullptr);

    return 0;
}

 RingQueue是采用信号量进行条件变量以及互斥量的控制.

首先认识一下信号量的接口:

int sem_wait(sem_t* sem): 相当于条件变量里面的pthread_cond_wait

int sem_post(sem_t* sem): 相当于mutex_unlock;

int sem_init(sem* sem): 相当于pthread_cond_init;

int sem_destroy(sem* sem): 相当于pthread_cond_destroy

 下图更好的理解环形队列生产消费模型;

生产者不能将消费者包个圈, 因为消费者没有消费, 那么空间资源就不会释放, 并且消费者也不能越过生产者, 因为消费者消费完生产者生产的数据, 那么还需要的数据并还没有生产.

这样就有两个变量需要控制一个是空间资源_space_sem, _data_sem; 以及生产者消费者的位置也需要记录_p_step, _c_step.

#pragma once

#include <iostream>
#include <vector>
#include <pthread.h>
#include <semaphore.h>
#include "LockGuard.hpp"

const int defaultsize = 5;

template <class T>
class RingQueue
{
private:
    void P(sem_t &sem)
    {
        sem_wait(&sem);
    }
    void V(sem_t &sem)
    {
        sem_post(&sem);
    }

public:
    RingQueue(int size = defaultsize)
        : _ringqueue(size), _size(size), _p_step(0), _c_step(0)
    {
        sem_init(&_space_sem, 0, size);
        sem_init(&_data_sem, 0, 0);

        pthread_mutex_init(&_p_mutex, nullptr);
        pthread_mutex_init(&_c_mutex, nullptr);
    }
    void Push(const T &in)
    {
        P(_space_sem);
        {
            LockGuard lockGuard(&_p_mutex);
            _ringqueue[_p_step] = in;
            _p_step++;
            _p_step %= _size;
        }
        V(_data_sem);
    }
    void Pop(T *out)
    {
        // 消费
        P(_data_sem);
        {
            LockGuard lockGuard(&_c_mutex);
            *out = _ringqueue[_c_step];
            _c_step++;
            _c_step %= _size;
        }
        V(_space_sem);
    }
    ~RingQueue()
    {
        sem_destroy(&_space_sem);
        sem_destroy(&_data_sem);

        pthread_mutex_destroy(&_p_mutex);
        pthread_mutex_destroy(&_c_mutex);
    }

private:
    std::vector<T> _ringqueue;
    int _size;

    int _p_step; // 生产者的生产位置
    int _c_step; // 消费位置

    sem_t _space_sem; // 生产者
    sem_t _data_sem;  // 消费者

    pthread_mutex_t _p_mutex;
    pthread_mutex_t _c_mutex;
};

常见生产者消费者线程, 借助上次使用过的Task类, 模拟生产这个数据, 然后进行push数据.

消费者就是popTask里面的数据结果.

注意: 创建的线程一定要join.

#include<iostream>
#include"Log.hpp"
#include"RingQueue.hpp"
#include"Task.hpp"
#include<pthread.h>
#include<ctime>
using namespace std;

void* Productor(void* args)
{
    RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(args);

    while(true)
    {
        int data1 = rand() % 10;
        usleep(rand() % 123);

        int data2 = rand() % 10;
        usleep(rand() % 123); 

        char oper = opers[rand() % (opers.size())];
        Task t(data1, data2, oper);
        cout << "productor task: " << t.PrintTask() << endl;

        rq->Push(t);
    }
    return nullptr;
}

void* consumer(void* args)
{
     RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(args);
     while(true)
     {
        Task t;
        rq->Pop(&t);

        t.Run();
        cout << "consumer done, data is : " << t.PrintResult() << endl;
     }
}

int main()
{
   /*  Log log;
    log.LogMessage(Debug, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(warning, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(Error, "hello %d, %s, %f", 10, "study", 3.14);
    log.LogMessage(Info, "hello %d, %s, %f", 10, "study", 3.14);
     */
    

    srand((uint64_t)time(nullptr) ^ pthread_self());
    pthread_t c[3], p[2];

    RingQueue<Task>* rq = new RingQueue<Task>();

    pthread_create(&p[0], nullptr, Productor, rq);
    pthread_create(&p[1], nullptr, Productor, rq);

    pthread_create(&c[0], nullptr, consumer, rq);
    pthread_create(&c[1], nullptr, consumer, rq);
    pthread_create(&c[2], nullptr, consumer, rq);

    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(c[2], nullptr);

    return 0;
}

3.线程池

3.1 线程池的概念:

线程池是一种线程使用的机制, 维护多个线程, 等待命令执行多线程并发的任务, 避免过多线程的调用带来太大开销, 导致影响性能. 好处是避免短时间的任务创建和销毁的开销, 保证内核的高效使用.

 3.2线程池使用的场景:

(1)需要大量线程完成, 并且任务时间短的;

(2)对性能要求比较高的应用;

(3)接受突发性大量请求;

3.3线程池的种类:

(1)创建固定数量的线程,池, 循环从队列里面拿任务;

(2)获取到任务之后, 执行任务对象的任务接口;

 3.4代码编写(单例模式的线程池)

#include <iostream>
#include <queue>
#include <vector>
#include <pthread.h>
#include <functional>

#include"Thread.hpp"
#include"LockGuard.hpp"
#include"Log.hpp"
#include"Task.hpp"

using namespace std;

class ThreadData
{
public:
    ThreadData(const string& name)
        :threadname(name)
    {}

    ~ThreadData()
    {}

    string threadname;
};

static const int defaultnum = 5;

template<class T>
class ThreadPool
{
private:
    ThreadPool(int thread_num = defaultnum)
        :_thread_num(thread_num)
    {
        pthread_mutex_init(&_mutex, nullptr);
        pthread_cond_init(&_cond, nullptr);

        for(int i = 0; i < _thread_num; i++)
        {
            string threadname = "thread-";
            threadname += to_string(i + 1);

            ThreadData td(threadname);

            _threads.emplace_back(threadname, bind(&ThreadPool<T>::ThreadRun, this, placeholders::_1), td);
            log.LogMessages(Info, "%s is create...\n", threadname.c_str());
        }
    }

    ThreadPool(const ThreadPool<T>& td) = delete;
    ThreadPool<T>& operator=(const ThreadPool<T>& td) = delete;
    
public:
    static ThreadPool<T>* GetInstance()
    {
        if(instance == nullptr)
        {
            LockGuard lockguard(&sig_lock);
            if(instance == nullptr)
            {
                log.LogMessages(Info, "创建单例成功!");
                instance = new ThreadPool<T>();
            }
        }
        return instance;
    }

    bool start()/* 启动线程池 */
    {
        for(auto& thread : _threads)
        {
            thread.Start();
            log.LogMessages(Info, "%s is running ...\n", thread.ThreadName().c_str());
        }
        return true;
    }

    void ThreadWait(const ThreadData& td)
    {
        log.LogMessages(Debug, "no task, %s is sleeping...\n", td.threadname.c_str());
        pthread_cond_wait(&_cond, &_mutex);
    }

    void ThreadWakeup()
    {
        pthread_cond_signal(&_cond);
    }

    void checkSelf()
    {
        /* 水位线检查 */
    }

    void ThreadRun(ThreadData& td) /* 模拟pop消费者消费数据 */
    {
        while(true)
        {
            checkSelf();
            T t;
            {
                LockGuard lockguard(&_mutex);
                while(_q.empty())
                {
                    ThreadWait(td);
                    log.LogMessages(Debug, "thread %s is wakeup\n", td.threadname.c_str());
                }
                t = _q.front();
                _q.pop();
            }
            
            Task t1;
            log.LogMessages(Debug, "%s handler task %s done, result is : %s\n",
                          td.threadname, t1.PrintTask().c_str(), t1.PrintResult().c_str());
        }
    }

    void Push(Task& in)
    {
        log.LogMessages(Debug, "other thread push a task, task is :%s \n", in.PrintTask().c_str());
        LockGuard lockguard(&_mutex);
        _q.push(in);
        ThreadWakeup();
    }

    ~ThreadPool()
    {
        pthread_mutex_destroy(&_mutex);
        pthread_cond_destroy(&_cond);
    }

    void wait()
    {
        for(auto&  thread : _threads)
        {
            thread.Join();
        }
    }
private:
    queue<T> _q;
    vector<Thread<ThreadData>> _threads;
    int _thread_num;
    pthread_mutex_t _mutex;
    pthread_cond_t _cond;

    static ThreadPool<T>* instance;
    static pthread_mutex_t sig_lock;
};

/* 对static变量外部初始化 */
template <class T>
ThreadPool<T> *ThreadPool<T>::instance = nullptr;
template <class T>
pthread_mutex_t ThreadPool<T>::sig_lock = PTHREAD_MUTEX_INITIALIZER;

#include <iostream>
#include <memory>
#include <ctime>
#include "ThreadPool.hpp"
#include "Task.hpp"
using namespace std;

int main()
{
    sleep(1);
    ThreadPool<Task>::GetInstance()->start();
    srand((uint64_t)time(nullptr) ^ getpid());
    
    while(true)
    {
        int x = rand() % 10;
        usleep(100);

        int y = rand() % 10;
        usleep(100);

        char oper = opers[rand() % opers.size()];
        Task t1(x, y, oper);

        ThreadPool<Task>::GetInstance()->Push(t1);
        sleep(1);
    }

    ThreadPool<Task>::GetInstance()->wait();
    return 0;
}

4. STL, 智能指针, 线程安全

(1) STL不是线程安全的, 如果要在线程里面使用需要配合锁使用.

(2) 智能指针中unique_ptr, 不是线程安全的;  shared_ptr因为是涉及到引用计数所以是原子的,也就是线程安全的.

 5.读者写者问题

在编写多线程的时候, 往往会出现修改的机会少, 读取的机会多, 在读取的时候互斥量的一系列处理就效率非常慢, 然后根据这种情况特定还有一种读写锁.

这里先认识一下读写锁的接口:

int pthread_rwlock_init: 读写锁的初始化

int pthread_rwlock_destroy: 读写锁的销毁

int pthread_rwlock_rdlock: 读锁的互斥量

int pthread_rwlock_wrlock: 写锁的互斥量

int pthread_rwlock_unlock: 读写锁的解锁.

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/596786.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

赚钱的背后逻辑!2024创业干什么最赚钱?2024创业方向!2024普通人的出路!2024普通人最有前景的行业!

钱根本不是赚来的。钱&#xff0c;是你帮别人解决问题后&#xff0c;对方给你的回报。什么时候把这句话理解透了&#xff0c;钱就会反过来追你。 问题就是每个人的痛点&#xff0c;痛点就是需求&#xff0c;男人怕穷&#xff0c;女人爱美&#xff0c;老人怕病&#xff0c;小孩怕…

OpenHarmony实战开发-管理位置权限

Web组件提供位置权限管理能力。开发者可以通过onGeolocationShow()接口对某个网站进行位置权限管理。Web组件根据接口响应结果&#xff0c;决定是否赋予前端页面权限。获取设备位置&#xff0c;需要开发者配置ohos.permission.LOCATION&#xff0c;ohos.permission.APPROXIMATE…

面试笔记——类加载器

基础 类加载器&#xff1a;用于装载字节码文件(.class文件)运行时数据区&#xff1a;用于分配存储空间执行引擎&#xff1a;执行字节码文件或本地方法垃圾回收器&#xff1a;用于对JVM中的垃圾内容进行回收 类加载器 &#xff1a;JVM只会运行二进制文件&#xff0c;类加载器的…

LLM——用于微调预训练大型语言模型(LLM)的GPU内存优化与微调

前言 GPT-4、Bloom 和 LLaMA 等大型语言模型&#xff08;LLM&#xff09;通过扩展至数十亿参数&#xff0c;实现了卓越的性能。然而&#xff0c;这些模型因其庞大的内存需求&#xff0c;在部署进行推理或微调时面临挑战。这里将探讨关于内存的优化技术&#xff0c;旨在估计并优…

2025第23届太原煤炭(能源)工业技术与装备展览会

第二十三届太原煤炭&#xff08;能源&#xff09;工业技术与装备展览会 邀 请 函 指导单位&#xff1a; 中国煤炭工业协会 主办单位&#xff1a;山西省煤炭工业协会 承办单位&#xff1a;太原奇新展览有限公司 展览时间&#xff1a;2025年4月22-24日 展览地点&#xff1a…

jenkins+gitlab+sonar自由风格项目配置

新建项目&基本配置 gitlab侧配置 sonar.projectKeytest_sonar sonar.projectNametest_sonar sonar.projectVersion1.0 sonar.sources. sonar.exclusionssrc/layout/** sonar.sourceEncodingUTF-8 sonar.nodejs.executable/app/nodejs/node-v16.20.2-linux-x64/bin/node配置…

cURL:命令行下的网络工具

序言 在当今互联网时代&#xff0c;我们经常需要与远程服务器通信&#xff0c;获取数据、发送请求或下载文件。在这些情况下&#xff0c;cURL 是一个强大而灵活的工具&#xff0c;它允许我们通过命令行进行各种类型的网络交互。本文将深入探讨 cURL 的基本用法以及一些高级功能…

智能AI摄像头项目

项目概要 硬件说明&#xff1a;易百纳rv1126 38板&#xff0c;易百纳GC2053摄像头&#xff0c;拓展版&#xff08;自绘&#xff09;&#xff0c;屏幕驱动板&#xff08;自绘&#xff09;&#xff0c;3.1inch mipi屏&#xff0c;FT5316触摸屏 开发环境 硬件分析 开发环境及sd…

数据结构十一:数组相关经典面试题

本篇博客详细介绍分析数组/顺序表常见的面试题&#xff0c;对于前面所学知识进行一个巩固&#xff0c;同时介绍一些力扣刷题中的一些概念&#xff1a;如&#xff1a;输出型参数等&#xff0c;在刷题中培养自己的编程思维&#xff0c;掌握常见的编程套路&#xff0c;形成题感&am…

KernelSU 如何不通过模块,直接修改系统分区

刚刚看了术哥发的视频,发现kernelSU通过挂载OverlayFS实现无需模块,即可直接修改系统分区,很是方便,并且安全性也很高,于是便有了这篇文章。 下面的教程与原视频存在差异,建议观看原视频后再结合本文章进行操作。 在未进行修改前,我们打开/system/文件夹,并在里面创建…

Junit 测试中如何对异常进行断言

本文对在 Junit 测试中如何对异常进行断言的几种方法进行说明。 使用 Junit 5 如果你使用 Junit 5 的话,你可以直接使用 assertThrows 方法来对异常进行断言。 代码如下: Exception exception = assertThrows(NumberFormatException.class, () -> {new Integer("on…

fiscobcos 3.x linux安装与java简单调用

所用环境 vmware 16 Pro centos7.6 jdk11.0.6 ideal 2022 1、安装fiscobcos # 创建操作目录 # cd ~ && mkdir -p fisco && cd fisco# 下载建链脚本 # curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v3.6.0/build_chain.sh &a…

Spring Security + JWT 实现登录认证和权限控制

Spring Security JWT 实现登录认证和权限控制 准备步骤 准备好一些常用的工具类&#xff0c;比如jwtUtil&#xff0c;redisUtil等。引入数据库&#xff0c;mybatis等&#xff0c;配置好controller&#xff0c;service&#xff0c;mapper&#xff0c;保证能够正常的数据请求。…

【python】条件语句与循环语句

目录 一.条件语句 1.定义 2.条件语句格式 &#xff08;1&#xff09;if &#xff08;2&#xff09;if-else &#xff08;3&#xff09;elif功能 &#xff08;4&#xff09;if嵌套使用 3.猜拳游戏 二.循环语句 1. while循环 2.while嵌套 3.for循环 4.break和conti…

k8s部署skywalking(helm)

官方文档 官方文档说明&#xff1a;Backend setup | Apache SkyWalking官方helm源码&#xff1a;apache/skywalking-helm官方下载&#xff08;包括agent、apm&#xff09;:Downloads | Apache SkyWalking 部署 根据官方helm提示&#xff0c;选择你自己部署的方式&#xff0c…

PyTorch深度学习框架:从入门到实战

前言 学习 PyTorch 深度学习框架之前先学会深度学习和卷积神经网络 CNN &#xff0c;这样学习起来会更香嗷。 Windows系统下PyTorch的环境配置 Anaconda是什么&#xff1a; Anaconda是一个开源的Python发行版本&#xff0c;专注于数据分析领域。它包含了conda、Python等190多…

解决python/pycharm中import导入模块时报红却能运行的问题

一、问题 导入时报红&#xff0c;如下 二、解决 右键单击项目&#xff0c;将项目Mark Directory as→Sources Root 三、效果 报红消失 学习导航&#xff1a;http://www.xqnav.top

Docker网络基础

简介 Docker 本身的技术依赖于近年来 Linux 内核虚拟化技术的发展,Docker 对 Linux 内核的特性有很强的依赖。Docker 使用到的与 Linux 网络有关的主要技术有:网络命名空间、veth 设备对、网桥、ipatables 、路由。 网络命名空间 为了支持网络协议栈的多个实例,Linux在网络栈…

使用Docker安装Jenkins

大家好&#xff0c;今天给大家分享如何使用docker安装jenkins&#xff0c;关于docker的安装和常用命令可以参考下面两篇文章&#xff0c;使用docker可以提高资源利用率&#xff0c;能够在不同的环境中轻松迁移和部署应用&#xff0c;在本文中就不过多赘述了。 Docker常用命令 …

大数据BI可视化(Echarts组件)项目开发-熟悉动画使用功能4.0

加载动画 数据源 [{ "gender": "female", "height": 161.2, "weight": 51.6 }, { "gender": "female", "height": 167.5, "weight": 59 }, { "gender": "female", &quo…
最新文章