'Implementation of Threads in c++

I'm trying to maintain two function with threads in c++ (Visual Studio supporting #include library), when I run function without parameter it runs fine but with parameters it popping up an error. Code is:

void fun(char a[])
{}

int main()
{
    char arr[4];
    thread t1(fun);
    //(Error    1   error C2198: 'void (__cdecl *)(int [])' : too few arguments for call) 

    thread t2(fun(arr));     
    //Error 1   error C2664: std::thread::thread(std::thread &&) throw()' : 
    //cannot     convert parameter 1 from'void' to 'std::thread &&' 
    //Second Error is 2 IntelliSense: no instance of constructor
    // "std::thread::thread" matches the argument list argument types are: (void

    return 0;
}

help me to handle this.



Solution 1:[1]

Take a look at this example:

https://mockstacks.com/Cpp_Threading

#include <string>
#include <iostream>
#include <thread>

using namespace std;

// The function we want to execute on the new thread.
void task1(string msg)
{
    cout << "task1 says: " << msg;
}

int main()
{
    // Constructs the new thread and runs it. Does not block execution.
    thread t1(task1, "Hello");

    // Do other things...

    // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
    t1.join();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daoud