Threat alive

In C++ you can provide concurrency by using threat.

join method creates waiting for the main thread. But detach stop connection between the main thread and created child thread.

Passing argument

You can also pass an argument to the thread. You can simply use the parameter on thread method.

But it creates several copies of the object. The best way is using pointer but you can’t pass pointer directly. There is a helper std:ref

on the other hand, you may use std:cref for constant references

Using the same variables with mutex

If multiple threads use a variable. You have to create a mutex system. A mutex has two important methods: lock and unlock.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *