c++ 并行:并行的一个小实验

 

 c++ 并行:并行的一个小实验

#include<iostream>
#include<thread>
void func1()
{
    std::cout<<"%%%%%%%%%%%%%%%%%%%"<<std::endl;
}
void func2()
{
    std::cout<<"$$$$$$$$$$$$$$$$$$$$$$"<<std::endl;
}
void func3()
{
    std::cout<<"&&&&&&&&&&&&&&&&&&&&&&&"<<std::endl;
}
void func4()
{
    std::cout<<"**********************"<<std::endl;
}
void func5()
{
    std::thread t1(func1);
    std::thread t2(func2);
    t1.join();
    t2.join();
}
void func6()
{
    std::thread t3(func3);
    std::thread t4(func4);
    t3.join();
    t4.join();
}
void func7()
{
    std::thread t1(func1);
    std::thread t2(func2);
    t1.join();
    t2.join();
}
int main()
{   std::thread t5(func5);
    std::thread t6(func6);
    t5.join();
    t6.join();
    //func7();
    return 0;
}

cmakelist

cmake_minimum_required(VERSION 2.8)
project(bingxing)

find_package (Threads)
add_executable(bingxing bingxing.cpp)
target_link_libraries(bingxing ${CMAKE_THREAD_LIBS_INIT})

build文件

mkdir build 
cd build
cmake ..
make

./bingxing

 

结果:

&&&&&&&&&&&&&&&&&&&&&&&
**********************
$$$$$$$$$$$$$$$$$$$$$$
%%%%%%%%%%%%%%%%%%%

 

上一篇:AndroidStudio3.5下用NDK编绎VulkanSceneGraph


下一篇:CMakeList 基础写法