Skip to main content

Posts

Showing posts from April, 2014

ACCU 2014 Conference - Bristol, UK

Last week I participated in ACCU 2014 Conference in Bristol (UK). That was great and fruitful time for me where I find out lot of information about C++ and Software development in general, as well as I met few interesting people. I would like to share few information from that conference with you. During the conference we listen interesting speeches of many C/C++ experts such as: Howard Hinnant - he presened interesting speech about C++11 Move Semantics , presenting interesting short explanation how std::move actually work as well as detail presentation of generation of Special Member Function (class members which are automatically generated by compiler) for different cases with and without move constructor and move assignment operator. At the end he presented detail implementation of basic move constructor and move assignment operator . Detail explanation of move semantics will be presented on this blog soon. Anthony Williams - author of book C++ Concurrency in Action and d

C++ Multithreading - Race conditions

In the previous C++ Multithreading article I presented you how to pass parameters between threads. Take a detail look on the output of that example once again: In the first line of that output you can notice that output text from two threads is mixed. You are probably wondering why it happens? It is because we are not protecting resources which are shared by two threads (in this example cout stream is shared in both threads) which causes multithreading's phenomenon called race condition . Because threads switching and accessing to shared resources are managed by operating system we do not know when std::cout stream will be accessed by main thread and when it will be accessed by second thread. Therefore in the previous article I mentioned that output of the example can be little different on your computer than my output example. What's more it is possible that this output will be different for few consecutive invoking of the example on the same machine. It is beca

C++ Multithreading - Passing parameters to thread function and sleep thread

Today I am going to present you second article about new C++11 Multithreading feature. I am going to present you how we can pass parameters to thread function (by value and by reference) as well as show you how to delay thread processing for selected amount of time . In previous C++ Multithreading article we presented how to create thread function and run second thread in parallel to main thread. Now we are extending that example with usage of another multithreding features. Let take a look on the new example: Output of that example could be (it can be little other output on your machine because we are working with Multithreading which is not protected by phenomenon called race condition which I will explain in one of another articles): In point I and II we are creating new thread which will invoke function print() from point Ia. Difference to the example from previus article is that we are passing two parameters to our function. First parameter firstParam is passed b

Advanced C++ - virtual functions

Today I am going to explain some basic but very important C++ feature - polymorphism and inheritance which is based on virtual functions in C++. Virtual functions can be declared by preceding the function with virtual keyword. The importance of Virtual functions can be understood, when we design classes using inheritance. Virtual functions are special functions which are called using late binding concept. Late binding or dynamic binding means that the binding happens during run time using vtable (virtual table) to select the correct virtual method to be called as the code runs. Let us look at an example for getting more clarity on how Virtual functions work in reality: Output of that example is: Point 1 shows how virtual function is declared and defined. Point 2 shows the inheritance concept i.e class Derived is inherited from class Base using public access specifier. In point 3, virtual function of class Base is redefined in class Derived which leads to f