Skip to main content

Posts

GDB Automatic Deadlock Detector

Have you ever had a problem with detection deadlock between threads in your C/C++ application? Would you like to do that automatically? Try this GDB Automatic Deadlock Detector from my github: GDB Automatic Deadlock Detector Picture source: http://csunplugged.org/wp-content/uploads/2015/03/deadlock.jpg1286488735
Recent posts

How to quickly investigate memory leak in your application

Every C/C++ software developer meet problem of memory leak (allocating memory over time which is not freed). If you would like to know how to investigate memory leak problem in your application, this article is for you. For memory leak investigation I recommend to use valgrind tool. Especially with it's Massif tool. Let's see the example how we could use that tool for memory leak investigation. Below snippet of code has lots of points where memory leak can occur. 1 #include <stdio.h> 2 3 void allocmem1 () 4 { 5 char * memleak 2 = malloc ( 100 * sizeof ( char )) ; 6 } 7 8 void allocmem2 () 9 { 10 char * memleak 2 = malloc ( 10 * sizeof ( char )) ; 11 allocmem1 () ; 12 } 13 14 void allocmem3 () 15 { 16 char * memleak 2 = malloc ( 5 * sizeof ( char )) ; 17 allocmem2 () ; 18 } 19 20 int main ( int argc , const char ** argv ) 21 { 22 char * memleak 1 = malloc ( 5 * sizeof ( char )) ; 23

How to speed-up make-based building process

If you are building some multifile-based project using make tool, it is worth to use parallel build in order to speed up building process. You can do that using -j option  of make tool ex. make -j2 If you will select -j2, you are informing your compiler to use 2 cores of your CPU for building process. The optimal option is to split build using all cores of your CPU. In order to get number of cores of your CPU on Linux-based OS you can use command: nproc Therefore, if you would like to speed-up build time optimally using all cores of you CPU, you can use following command on Linux-based OS: make -j`nproc` Picture source: http://hostme.ie/wp-content/uploads/2011/03/speed-up-wordpress.jpg

Linux - VIM as Integrated Development Environment (IDE)

In this post I would like to present you my configuration of vim text editor as Integrated Development Environment (IDE). In my daily work I am not using big IDE environments like Eclipse, NetBeans or other. Instead, I am using vim text editor configured with number of plugins, which contains all of most important features of traditional IDE environment and additionally I don't need to resign with VIM advantages like speed and flexibility. Using that VIM as IDE configuration I comfortably work with following programming languages on the daily basis: C/C++ Java Python Bash JavaScript HTML CSS My VIM as IDE configuration is publically available in github. You can clone it from here: git clone https://github.com/xmementoit/vim-ide It is under continous development so you can expect adding new features in the future. Video presentation of main features of my VIM as IDE environment can be found on youtube: I am aware that starting with big VIM as IDE configurati

Bash - useful bash aliases which I use in my daily work

~/projects/CppAdventureExamples/bash/aliases.html Bash alias is abbreviation of one terminal command (usually long command) using other terminal command (usually much shorter command). We can define aliases in bash dot files (ex. ~/.profile file). Example of bash alias: alias i="sudo apt-get install" Then we can install 'vim' package using 'i' alias this way (it works of Debian-based systems): i vim Today I would like to present few useful bash aliases which I use in my daily work. You can paste below aliases into your ~/.profile file (or ~/.bashrc) if you recognize them useful for you. Enjoy! #================================================================== # Listing aliases alias ll= "ls -lah" #list only directoriesj alias lsd= "ls -lF ${colorflag} | grep --color=never '^d'" alias sl= 'ls' #================================================================== #filter selected app fro

Bash - parallel operations

Today I would like to present useful tool for every Linux developer - bash parallel mode. Bash parallel mode allows to invoke multiple bash tasks (ex. functions, linux applications etc.) in parallel, which could save time of processing them. What's is more, usage of bash parallel mode is very simple and does not require lot of work. Let's explain it based on the examples. We are starting with bash script working in seqence mode (one function invoked after previous one). We defind function task() which is later invoked in for loop 10 times. Invoking of each instance of function takes SLEEP_TIME=2 seconds. So script invokation takes 10x2s == 20 seconds. Now, lets change above script in order to work in parallel mode: Please note few small, but important changes between above scripts: < invokation of function task has '&' character at the end. It means that function will be invoked in background and will not block main thread of script. functio

C++11 Multithreading - How to avoid race conditions

This article presents how to avoid problem of Race conditions described in this article. As we already know race conditions can occur when two or more threads are trying to invoke some part of code or use the same resource (ex. variable) at the time. That can cause problem of unexpected results. We could see that problem in 'Race conditions' article where two threads was able to modify the same variable value which caused different program output every time we invoked it. In order to avoid that problem we should synchronize operations of our threads using multithreading mechanism called mutexes (abbr. Mutual exclusion ). Mutex is some kind of program flow control lock which which is able to make sure that some part of code locked by itself can be invoked by only one thread at the same time. Such locked part of code is called critical section . When other thread will try to go into critical section it will be blocked and will need to wait until previous thread