How to enable MultiThreading in C++?



Hey guys when i right this code in C++:

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

void func_1(){
    std::cout << "Thread 1 Exectuting" << std::endl;
int main(){
    std::thread t1(func_1);
    /*Main Threads
    **Wait for t1 thread to finish..
    **Just like go

And hit Ctrl+shift+b:

This comes up:

terminate called after throwing an instance of 'std::system_error'                                                              
  what():  Enable multithreading to use std::thread: Operation not permitted                                                    
bash: line 12:  9798 Aborted                 $file.o $args


How did you compile it?



I use c9 for web development so I have no C++ experience in c9. But I did create a C++ workspace and I tried some threading and it was unable compile.


I haven’t touched C++ in years, but it seems that your main method is missing a return statement. Something like return 1 perhaps.


That dosent work @BigChief45 , these days you dont need to return, if it is the original no-param Main method.


@vasilenko93 , @BigChief45, and anyone facing this problem i gotta solution for yall! :boom:


g++ main.cpp -o main.out -pthread -std=c++11

Change main.cpp with your file name… and then to run it



Yeah did some extra research and the -pthread was missing.