Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if (e.g) we have one thread, what will thread do? and can we execute the code outside the thread?

Lastly, which low-level OS specific functions are used to implement std::thread/boost::thread/pthread in Windows and what is more flexible and more simpler: low-level functions or classes.
Posted

1 solution

Every process starts with a single thread. So what there is no way to execute any code outside a thread. You always have at least one thread. And in the times before multi-thread was introduced, the entire program ran in that single thread, which is sometimes called the default thread or the main thread.

As for the Windows functions: Google is your friend! It's easy to look them up in the Windows API.

The question of using a class library or low-level function: In most practical cases you will be using a class library, for instance boost. This prevents you from making common mistakes (which are easily to be made in such a complicated subjects). Very rarely do you need to resort to the low-level functions, because you want to do somethings the class library is not able to do. In such cases you however give up the easy portability of your code, which is a great plus when using a good class library.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Dec-15 16:02pm    
5ed.
—SA
nv3 27-Dec-15 16:17pm    
Thanks!
Albert Holguin 29-Dec-15 10:55am    
+5... Also worth noting std::thread is relatively new and is basically a standardized version of what boost::thread was (C++ did not include multithreading until recently, meaning all systems implemented their own version). pthread is the POSIX standard but it's not natively supported by Windows.... Windows has its own WinAPI threading calls.
nv3 29-Dec-15 11:06am    
Thanks for this comment, Albert. Good point.
Albert Holguin 29-Dec-15 14:40pm    
Since the OP seems to be new to multithreading figured the extra info would help them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900