• Linux 新建线程 简单使用


    PS:在 Android 下运行正常。

    #include "MainWindow.h"
    #include "ui_MainWindow.h"
    
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    int main_z();
    
    void MainWindow::on_pushButton_clicked()
    {
        main_z();
    }
    
    
    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<pthread.h>
    #include<errno.h>
    #include<unistd.h>
    
    void* thread1(void*);
    
    int main_z()
    {
        qDebug() << "main_z in";
        pthread_t tid1;
        int rc1=0;
    
        rc1 = pthread_create(&tid1, NULL, thread1, &tid1);
        if(rc1 != 0)
        {
            QString str1 = __func__;
            QString str2 = strerror(rc1);
            qDebug() << str1 + str2;
        }
        qDebug() << "main_z out";
        //exit(0);
    }
    
    void* thread1(void* arg)
    {
        qDebug() << "thread1 in";
        ushort us = (unsigned int)pthread_self();
        qDebug() << "this is thread1, thread id is " +QString::number(us);
        qDebug() << "thread1 out";
        pthread_exit(0);
    }
    

      

  • 相关阅读:
    实验三 面向对象分析与设计
    实验二 结构化分析与设计
    软件开发文档与工具的安装与使用
    ATM管理系统
    活动图与流程图
    四则运算
    实验四 决策树算法及应用
    实验三 朴素贝叶斯算法及应用
    实验二 K-近邻算法及应用
    实验一 感知器及其应用
  • 原文地址:https://www.cnblogs.com/codeskilla/p/4933619.html
Copyright © 2020-2023  润新知