C++ 11 feature: C++ Multithreading Tutorial: Unique Lock in C++ threading
In the previous chapter we saw lock_guard. In this chapter we shall learn unique lock. Unique lock is a class that is available form C++ 11. Unique lock is a wrapper over a mutex. It will own the mutex that is passed to unique lock. A unique lock has below features: 1. A unique lock […]
C++ 11 feature: C++ Multithreading Tutorial: Lock Guard in C++ threading
In this chapter we shall learn about lock guard. 1. lock_guard is a class in C++ 2. lock_guard provides RAII style mechanism for acquiring mutex for a scoped block. 3. lock_guard acquires mutex the moment you create an object of lock_guard. 4. When the control leaves the scope, it will automatically unlocks and lock_guard object […]
C++ 11 feature: C++ Multithreading Tutorial: Recursive mutex in C++ threading
In the previous chapter we learn about timed_mutex, in this chapter we shall learn about recursive_mutex. Need for recursive mutex? Suppose there is a recursive function that acquires lock before calling itself as shown below: recursive_function() { . . . m.lock(); recursive_function(); m.unlock(); } Now the thread T1 will enter the function and locks itself. […]
C++ 11 feature: C++ Multithreading Tutorial: Timed mutex in C++ threading
In the previous chapters we learnt about Mutex, Race condition and critical section. In this chapter we shall learn about timed mutex. Generally in a mutex, when one thread tries to acquires a lock [T2], that has already been locked by another thread [T1], current thread [T2] will wait for a period of time till […]
C++ 11 feature: C++ Multithreading Tutorial: Mutex Try Lock in C++ threading
In the previous chapter we learn about mutex. In this chapter we shall learn about try_lock member function in mutex. As explained in the previous statement, try_lock is a member function of mutex class. There are different types of try_lock functions available. They are: There are 9 different try_lock member functions available: 1. std::try_lock 2. […]
C++ 11 feature: C++ Multithreading Tutorial: Mutex in C++ threading
In this chapter we shall learn about below topics; Mutex stands for Mutual Exclusion. What is mutual exclusion? To answer this question, we need to understand what is Race Condition? A race condition is a situation where two or more threads or process trying to modify the data at the same time. Race condition occurs […]
C++ 11 feature: C++ Multithreading Tutorial: Attaching and detaching threads in C++
In the first 2 chapters we saw an introduction and different ways to create a thread in C++. In this chapter we shall see ways to attach and detach a thread. Joining a thread using “join()”. Why there is a need to call join()? Once we create a thread, the main program needs to wait […]
Cpp Multi-Threading : Different ways to create a thread in C++
In the previous chapter we saw an introduction to threads and how thread is usedul to increase the execution time. In this chapter we shall see in how many ways we can create a thread. There are 5 different ways to create a thread: 1. Function Pointers 2. Lambda Functions 3. Functors 4. Member Functions […]
Cpp Multi-Threading Introduction
Introduction: A thread is a smallest unit of program execution. These threads can run in parallel and can increase efficiency and decrease execution time of a program. A thread reside inside of a process. In these multi threading chapters, it deals with C++ threading concepts rather than OS threading concepts. Every process by default will […]
CPP STL Tutorial : C++ Binary search operation that can be performed on containers
Binary search can be performed on sorted data. lower_bound : It will return an iterator pointing to the first element in the range [first,last) which does not compare less than val. upper_bound : It will return an iterator pointing to the first element in the range [first,last) which compares greater than val. equal_range : It […]