【Linux】第四十二站:线程局部存储与线程分离

news2024/10/5 16:26:21

一、线程的局部存储

1.实现多线程

如果我们想创建多线程,我们可以用下面的代码类似去实现

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
#define NUM 10

struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    threadData *td = static_cast<threadData*>(args);

    int i = 0;
    while(i < 10)
    {
        cout << "pid: " << getpid() << ", tid : " << toHex(pthread_self()) << ", threadname : " << td->threadname << endl;
        sleep(1);
        i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
        sleep(1);
    }
    for(int i = 0; i < tids.size(); i++)
    {
        pthread_join(tids[i], nullptr);
    }

    return 0;
}

运行结果如下图所示

image-20240229203441892

在这里我们就发现了一个问题:

所有的线程,执行的都是这个函数

一旦一个线程修改了数据,其他线程看到这个数据都会被修改


2.线程有独立的栈结构

当代码如下的时候

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
#define NUM 3

struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    int i = 0;
    while(i < 10)
    {
        cout << "pid: " << getpid() << ", tid : " << toHex(pthread_self()) 
        << ", threadname : " << td->threadname 
        << ", test_i: " << test_i << ", &test_i: " << toHex((pthread_t)&test_i) << endl;

        sleep(1);
        i++;
        test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
        sleep(1);
    }
    for(int i = 0; i < tids.size(); i++)
    {
        pthread_join(tids[i], nullptr);
    }

    return 0;
}

运行结果为:

image-20240229204957681

我们可以看到每一个线程的test_i都会独立的增长,并且每个test_i的地址都不一样

这是因为每一个线程都会有自己独立的栈结构。


3.线程之间没有秘密

那么如果我们主线程就想要访问上面线程1的变量,我们可以做到吗?当然可以做到,因为它也在同一个地址空间中。

就比如下面的代码就可以实现主线程访问线程2的变量

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
#define NUM 3

int *p = NULL;

struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    if(td->threadname == "thread-2")
    {
        p = &test_i;
    }
    int i = 0;
    while(i < 10)
    {
        cout << "pid: " << getpid() << ", tid : " << toHex(pthread_self()) 
        << ", threadname : " << td->threadname 
        << ", test_i: " << test_i << ", &test_i: " << &test_i << endl;

        sleep(1);
        i++;
        test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
    }
    sleep(1); //确保复制成功
    cout << "main thread get a thread local value, val: " << *p << ", &val: " << p << endl;   

    for(int i = 0; i < tids.size(); i++)
    {
        pthread_join(tids[i], nullptr);
    }

    return 0;
}

运行结果为:

image-20240229211018969

所以其实在线程和线程当中没有秘密,只不过我们要求每一个线程有自己独立的栈,但是他们还在通一个地址空间中,线程的栈上的数据,也是可以被其他线程看到并且访问的。如果我们一个线程想要访问另一个线程的值,当然可以访问,只不过我们平时禁止这样做。


4.线程的局部存储

如下所示,代码是多线程访问同一个变量的代码

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
#define NUM 3

//int *p = NULL;

int g_val = 100;

struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    //int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    // if(td->threadname == "thread-2")
    // {
    //     p = &test_i;
    // }
    int i = 0;
    while(i < 10)
    {
        cout << "pid: " << getpid() << ", tid : " << toHex(pthread_self()) 
        << ", threadname : " << td->threadname 
        << ", g_val: " << g_val << ", &g_val: " << &g_val << endl; 

       // << ", test_i: " << test_i << ", &test_i: " << &test_i << endl;

        sleep(1);
        i++;
        g_val++;
      //  test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
    }
    sleep(1); //确保复制成功
   // cout << "main thread get a thread local value, val: " << *p << ", &val: " << p << endl;   

    for(int i = 0; i < tids.size(); i++)
    {
        pthread_join(tids[i], nullptr);
    }

    return 0;
}

运行结果为:

image-20240229212555074

所以全局变量是被所有的线程看到并同时访问的。

这个g_val就是共享资源。


但是如果一个线程想要一个私有的全局变量呢?

所以我们可以下面这样做:在全局变量之前加上**__thread**

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
#define NUM 3

//int *p = NULL;

__thread int g_val = 100;

struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    //int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    // if(td->threadname == "thread-2")
    // {
    //     p = &test_i;
    // }
    int i = 0;
    while(i < 10)
    {
        cout << "pid: " << getpid() << ", tid : " << toHex(pthread_self()) 
        << ", threadname : " << td->threadname 
        << ", g_val: " << g_val << ", &g_val: " << &g_val << endl; 

       // << ", test_i: " << test_i << ", &test_i: " << &test_i << endl;

        sleep(1);
        i++;
        g_val++;
      //  test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
    }
    sleep(1); //确保复制成功
   // cout << "main thread get a thread local value, val: " << *p << ", &val: " << p << endl;   

    for(int i = 0; i < tids.size(); i++)
    {
        pthread_join(tids[i], nullptr);
    }

    return 0;
}

运行结果为

image-20240229213247688

这样的对一个变量加上__thread的,我们将这个称作线程的局部存储

而我们前面正好就说了:在线程的tcb中,就有一个线程的局部存储

image-20240229213409277

所以我们可以明显看到,这个变量应该就在动态库中存储着。

这个__thread其实就是编译器编译时候的一个默认选项

我们也可以直接从前面的两个图中的地址可以看出,没加这个选项的地址比较小(在静态区),加上这个选项地址比较大(处于堆栈之间的共享区)。

注意:这个__thread选项只能定义内置类型,不能用来修饰自定义类型

有了这个选项,对于某些只属于这个线程的变量,我们可以使用这个__thread来进行修饰,让它变为局部存储。这样的好处是可以不用频繁的去调用某些系统调用接口。

image-20240229214128231

这样就实现了线程级别的全局变量,和其他线程互不干扰。

二、分离线程

  • 默认情况下,新创建的线程是joinable的,线程退出后,需要对其进行pthread_join操作,否则无法释放资源,从而造成系统泄漏。
  • 如果不关心线程的返回值,join是一种负担,这个时候,我们可以告诉系统,当线程退出时,自动释放线程资源
#include <pthread.h>
int pthread_detach(pthread_t thread);
//Compile and link with -pthread.

这个分离接口既可以由主线程来做,也可以由其他新线程来做


我们可以先在join前先分离一下,看看是什么结果

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
#define NUM 3

//int *p = NULL;

__thread int g_val = 100;
__thread int number = 0;
struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    //int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    number = pthread_self();
    // if(td->threadname == "thread-2")
    // {
    //     p = &test_i;
    // }
    int i = 0;
    while(i < 10)
    {
        //cout << "number: " << number << ", pid: " << getpid() << endl;
        printf("number: 0x%x, pid: %d\n", number, getpid());
        //cout << "pid: " << getpid() << ", tid : " << toHex(number) << ", threadname : " << td->threadname << ", g_val: " << g_val << ", &g_val: " << &g_val << endl;         
        // << ", test_i: " << test_i << ", &test_i: " << &test_i << endl;
        sleep(1);
        i++;
        g_val++;
      //  test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
    }
    usleep(100000); //确保复制成功
    // cout << "main thread get a thread local value, val: " << *p << ", &val: " << p << endl;   

    for(auto i : tids)
    {
        pthread_detach(i);
    }

    for(int i = 0; i < tids.size(); i++)
    {
        int n = pthread_join(tids[i], nullptr);
        printf("n = %d, who = 0x%x, why: %s\n", n , tids[i], strerror(n));
    }
 
    return 0;
}

运行结果为:

image-20240301162551454

可见我们将线程给detach以后,再去join就不会成功了


我们也可以线程自己把自己分离掉

#include <iostream>
#include <pthread.h>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
#define NUM 3

//int *p = NULL;

__thread int g_val = 100;
__thread int number = 0;
struct threadData
{
    string threadname;
};
string toHex(pthread_t tid)
{
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "0x%x", tid);
    return buffer;
}
void* threadRoutine(void* args)
{
    pthread_detach(pthread_self());
    //int test_i = 0;
    threadData *td = static_cast<threadData*>(args);
    number = pthread_self();
    // if(td->threadname == "thread-2")
    // {
    //     p = &test_i;
    // }
    int i = 0;
    while(i < 10)
    {
        //cout << "number: " << number << ", pid: " << getpid() << endl;
        printf("number: 0x%x, pid: %d\n", number, getpid());
        //cout << "pid: " << getpid() << ", tid : " << toHex(number) << ", threadname : " << td->threadname << ", g_val: " << g_val << ", &g_val: " << &g_val << endl;         
        // << ", test_i: " << test_i << ", &test_i: " << &test_i << endl;
        sleep(1);
        i++;
        g_val++;
      //  test_i++;
    }

    delete td;
    return nullptr;
}


void InitThreadData(threadData* td, int number)
{
    td->threadname = "thread-" + to_string(number); 
}

int main()
{
    vector<pthread_t> tids;
    for(int i = 0; i < NUM; i++)
    {
        //注意这种方式不可以,因为都在主线程的栈中定义的变量。一旦for循环每循环一次
        //td也要随之销毁掉。这里传入的全部都是野指针了。
        // threadData td;
        // td.threadname = "";
        // td.tid = "";
        pthread_t tid;
        threadData *td = new threadData;
        InitThreadData(td, i);
        pthread_create(&tid, nullptr, threadRoutine, td);
        tids.push_back(tid);
    }
    usleep(100000); //确保复制成功
    // cout << "main thread get a thread local value, val: " << *p << ", &val: " << p << endl;   

    // for(auto i : tids)
    // {
    //     pthread_detach(i);
    // }

    for(int i = 0; i < tids.size(); i++) 
    {
        int n = pthread_join(tids[i], nullptr);
        printf("n = %d, who = 0x%x, why: %s\n", n , tids[i], strerror(n));
    }
 
    return 0;
}

运行结果也是一样的

image-20240301162921478

当线程内部的函数结束之后,会自动释放掉线程的资源


我们上面两个例子会发现一个问题,那就是分离线程应该会在线程跑完之后进行回收的。但是为什么还没有跑完就被回收了呢。这是因为我们在下面就有一个join,去等待了线程了。它在等待的发现已经被分离了。就不是阻塞式的等了,立马就出错返回了。出错返回后,这个for循环立刻就跑完了,跑完之后,主线成结束了,所以进程就结束了。所以虽然上面的线程还没有跑完,但是进程已经结束了,这些资源也就被释放了。

这里也告诉我们,即便我们的主线程将线程分离了,不用等待了,但是我们还是要自己去确保主线程是最后退出的,否则会出现一些问题。

所以线程是否被分离其实就是一个属性状态。它一定是要被存储的。所以线程分离其实就是将这个属性进行了修改

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AI智能答题系统是什么?

AI智能答题系统是一种基于人工智能技术的智能问答系统&#xff0c;旨在提供精准、高效的答题解答服务。该系统利用自然语言处理&#xff08;NLP&#xff09;、机器学习、知识图谱等多种技术&#xff0c;可以理解用户提出的问题&#xff0c;并在庞大的知识库或数据集中查找相关信…

鸿蒙报错:Hhvigor Update the SDKs by going to Tools > SDK Manager....

鸿蒙报错&#xff1a;Hhvigor Update the SDKs by going to Tools > SDK Manager… 打开setting里面的sdk&#xff0c;将API9工程下的全部勾上&#xff0c;应用下载 刚打开 js 和 Native 是没勾上的

LeetCode-102.题: 二叉树的层序遍历(原创)

【题目描述】 给你二叉树的根节点 root &#xff0c;返回其节点值的 层序遍历 。 &#xff08;即逐层地&#xff0c;从左到右访问所有节点&#xff09;。 示例 1&#xff1a; 输入&#xff1a;root [3,9,20,null,null,15,7] 输出&#xff1a;[[3],[9,20],[15,7]] 【题目链接…

Linux进程概念僵尸进程孤儿进程

文章目录 一、什么是进程二、进程的状态三、Linux是如何做的&#xff1f;3.1 R状态3.2 S状态3.3 D状态3.4 T状态3.5 t状态3.6 X状态3.7 Z状态 四、僵尸进程4.1 僵尸进程危害 五、孤儿进程 一、什么是进程 对于进程理解来说&#xff0c;在Windows上是也可以观察到的&#xff0c…

数据结构与算法第三套试卷小题

1.删除链表节点 **分析&#xff1a;**首先用指针变量q指向结点A的后继结点B&#xff0c;然后将结点B的值复制到结点A中&#xff0c;最后删除结点B。 2.时间复杂度的计算 **分析&#xff1a;**当涉及嵌套循环的时候&#xff0c;我们可以直接分析内层循环即可&#xff0c;看内…

sql注入基础学习

1.常用SQL语句 01、显示数据库 show databases&#xff1b; 02、打开数据库 use db name&#xff1b; 03、显示数据表 show tables&#xff1b; 04、显示表结构 describe table_name&#xff1b; 05、显示表中各字段信息&#xff0c;即表结构 show columns from table_nam…

【框架学习 | 第五篇】SpringMVC(常用注解、获取请求参数、域对象共享数据、拦截器、异常处理、上传/下载文件)

文章目录 1.SpringMVC简介1.1定义1.2主要组件1.3工作流程1.3.1简要流程1.3.2详细流程 1.4优缺点 2.常用注解3.获取请求参数3.1通过 HttpServletRequest 获取请求参数3.2通过控制器方法的形参获取请求参数3.2.1请求路径参数与方法形参一致3.2.2请求路径参数与方法形参不一致3.2.…

笔记本电脑使用时需要一直插电吗?笔记本正确的充电方式

随着科技的不断发展&#xff0c;笔记本电脑已经成为人们日常生活和工作中不可或缺的电子设备。而在使用笔记本电脑时&#xff0c;很多人会有一个疑问&#xff0c;那就是笔记本电脑使用时需要一直插电吗&#xff1f;本文将就此问题展开讨论。 不一定需要一直插电&#xff0c;如果…

C++:2024/3/11

作业1&#xff1a;编程 要求&#xff1a;提示并输入一个字符串&#xff0c;统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数 代码&#xff1a; #include <iostream>using namespace std;int main() {string str;cout << "请输入一个字…

sql-mysql可视化工具Workbench导入sql文件

mysql可视化工具Workbench导入sql文件 1、打开workbench2、导入sql文件3、第一行加上库名4、开始运行 1、打开workbench 2、导入sql文件 3、第一行加上库名 4、开始运行

参与Penpad launch任务,实现Penpad与Scroll的双空投

在比特币 ETF 、BTC 减半等利好消息的持续推动下&#xff0c;加密市场逐渐进入到新一轮牛市周期中。除了以太坊 Layer1 生态 TVL 不断飙升外&#xff0c;Layer2 赛道 TVL 也在不断飙升并且屡创新高。 而在牛市背景下&#xff0c;Layer2 空投所带来的财富效应预期正在被进一步拉…

IAB视频广告标准《数字视频和有线电视广告格式指南》之 目录和概述及视频配套广告 - 我为什么要翻译介绍美国人工智能科技公司IAB系列(2)

写在前面 谈及到中国企业走入国际市场&#xff0c;拓展海外营销渠道的时候&#xff0c;如果单纯依靠一个小公司去国外做广告&#xff0c;拉渠道&#xff0c;找代理公司&#xff0c;从售前到售后&#xff0c;都是非常不现实的。我们可以回想一下40年前&#xff0c;30年前&#x…

Facebook商城号为什么被封?如何防封?

由于Facebook商城的高利润空间&#xff0c;越来越多的跨境电商商家注意到它的存在。Facebook作为全球最大、用户量最大的社媒平台&#xff0c;同时也孕育了一个巨大的商业生态&#xff0c;包括广告投放、商城交易等。依托背后的大流量&#xff0c;Facebook商城起号较快&#xf…

接口测试\接口测试脚本之Jsoup解析HTML

第一次接触jsoup还是在处理收货地址的时候&#xff0c;当时在写一个下单流程&#xff0c;需要省市区id以及详细门牌号等等&#xff0c;因此同事介绍了jsoup,闲来无事&#xff0c;在此闲扯一番&#xff01; 1.我们来看下&#xff0c;什么是jsoup,先来看看官方文档是怎么说的&am…

【深度学习】换脸新科技,InstantID: Zero-shot Identity-Preserving Generation in Seconds

论文&#xff1a;https://arxiv.org/abs/2401.07519 代码:https://github.com/InstantID/InstantID demo&#xff1a;https://huggingface.co/spaces/InstantX/InstantID 文章目录 1 引言2 相关工作2.1 文本到图像扩散模型2.2 主题驱动的图像生成2.3 保持ID的图像生成 3 方法3.…

深入理解Vue.js中的nextTick:实现异步更新的奥秘

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

【wps】wps与office办公函数储备使用(结合了使用案例 持续更新)

【wps】wps与office办公函数储备使用(结合了使用案例 持续更新) 1、TODAY函数 返回当前电脑系统显示的日期 TODAY函数&#xff1a;表示返回当前电脑系统显示的日期。 公式用法&#xff1a;TODAY() 2、NOW函数 返回当前电脑系统显示的日期和时间 NOW函数&#xff1a;表示返…

群晖NAS使用Docker安装WPS Office并结合内网穿透实现公网远程办公

文章目录 推荐1. 拉取WPS Office镜像2. 运行WPS Office镜像容器3. 本地访问WPS Office4. 群晖安装Cpolar5. 配置WPS Office远程地址6. 远程访问WPS Office小结 7. 固定公网地址 推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff…

美国国家安全局(NSA)和美国政府将Delphi/Object Pascal列为推荐政府机构和企业使用的内存安全编程语言

上周&#xff0c;美国政府发布了《回到构建块&#xff1a;通往安全和可衡量软件的道路》的报告。本报告是美国网络安全战略的一部分&#xff0c;重点关注多个领域&#xff0c;包括内存安全漏洞和质量指标。 许多在线杂志都对这份报告发表了评论&#xff0c;这些杂志强调了对 C…

OpenCV学习笔记(五)——图片的缩放、旋转、平移、裁剪以及翻转操作

目录 图像的缩放 图像的平移 图像的旋转 图像的裁剪 图像的翻转 图像的缩放 OpenCV中使用cv2.resize()函数进行缩放&#xff0c;格式为&#xff1a; resize_imagecv2.resize(image,(new_w,new_h),插值选项) 其中image代表的是需要缩放的对象&#xff0c;(new_w,new_h)表…