A Question About Threads

How could someone make two threads that can operate in the background without disrupting the flow of a program. I am trying to do this for an IRC Client but I can't get it right.
I tried using regular threads they seem not to work.
"They seem not work" is pretty vague. It's going to be very difficult to help you with just that information.

What happened when you did this?
std::thread first (function_to_run_in_thread);
This is a the program in question and I expect no one to read it.
https://drive.google.com/file/d/0B4fqFvNG5t5oclMwLVM5WWhiejg/view?pref=2&pli=1

But this is an exemplar of the problem I am talking about.
1
2
3
4
5
6
7
8
9
10
11
void loop()
{
while(true){}
}

void main()
{
start loopThread1(loop);
start loopThread2(loop);
// program cannot halt after the start of threads
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <atomic>
#include <thread>

std::atomic<bool> exiting(false);

void loop()
{
    while (!exiting)
        ;
}

int main()
{
    std::thread t1(loop);
    std::thread t2(loop);

    exiting = true;

    t1.join();
    t2.join();
}
Topic archived. No new replies allowed.