March 2015

Semaphores are Surprisingly Versatile --Jeff Preshing

An interesting approach on how semaphores could be used in Modern C++ multithreaded programming:

Semaphores are Surprisingly Versatile

by Jeff Preshing

From the article:

In multithreaded programming, it’s important to make threads wait. They must wait for exclusive access to a resource. They must wait when there’s no work available. One way to make threads wait – and put them to sleep inside the kernel, so that they no longer take any CPU time – is with a semaphore.

I used to think semaphores were strange and old-fashioned. They were invented by Edsger Dijkstra back in the early 1960s, before anyone had done much multithreaded programming, or much programming at all, for that matter. I knew that a semaphore could keep track of available units of a resource, or function as a clunky kind of mutex, but that seemed to be about it.

My opinion changed once I realized that, using only semaphores and atomic operations, it’s possible to implement all of the following primitives:

  1. A Lightweight Mutex
  2. A Lightweight Auto-Reset Event Object
  3. A Lightweight Read-Write Lock
  4. Another Solution to the Dining Philosophers Problem
  5. A Lightweight Semaphore With Partial Spinning ...

Refactoring my Qt database code

I spend some time on refactoring my database code in Qt:

Refactoring my Qt database code

by Jens Weller

From the article:

For two days I had the chance to clean up my code and do a little refactoring. One of the results is, that my database code now also uses variadic templates. For some time now, I use Qt as the UI and Database frontend of my applications...

How Much Should You Pay Your Enginners? (Infographic) -- Cheyenne Richards

techsalaryguide15.PNG

We take all published measurements with a grain of salt, but we weight in favor of those based on interview data -- it's more difficult to gather, but far more accurate, than those based on heuristics applied to automated web search queries.

How Much Should You Pay Your Enginners? (Infographic)

by Cheyenne Richards

Hat tip to Kira M. Newman reporting at tech.coFrom Newman's intro:

Today, Startup Compass released the results of a global survey of engineers that provides a wealth of information about startup salaries -- including the highest-paying programming languages.

Published as “How Much Should You Pay Your Engineers?,” the results are based on a study of Startup Compass members plus data pulled from oDesk, Elance, Toptal, Glassdoor, AngelList, and Payscale...

One conclusion from the data, that resonates with C++ hiring managers: There is no oversupply of capable C++ developers.

Join our C/C++ compiler experts at the first annual #OpenPOWER summit next week -- Larry Lindsay

openpower15.PNGIf you're in the San Francisco Bay area, you might be interested in this from IBM:

Join our C/C++ compiler experts at the first annual #OpenPOWER summit next week

by Larry Lindsay

From the announcement:

Next week the First Annual OpenPOWER Summit takes place in San Jose, California from March 17-19... The XL C/C++ compiler team will be presenting two sessions on the latest compilation technology advancements...

CppCon 2014 Accept No Visitors--Yuriy Solodkyy

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

Accept No Visitors

by Yuriy Solodkyy

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Visitor Design Pattern was an attempt to overcome a limitation of object-oriented languages - inability to retroactively introduce new polymorphic functions. While it was quite efficient in providing extensibility of functions, it was never truly retroactive, easy to teach, use or maintain, and it achieved this at the cost of hindering extensibility of classes, introduction of control inversion and requiring tons of boilerplate code to be written. Visitor Design Pattern is a workaround, not a solution to the problem and in this talk I would like to discuss a more elegant yet as efficient solution in the form of a Match statement. We will look at several use-cases for the Visitor Design Pattern, their encoding using both approaches and ultimately their advantages and disadvantages.

CppCast Episode 3: Cross Platform Mobile C++ in Visual Studio with Ankit Asthana -- Rob Irving

Episode 3 of CppCast, the only podcast by C++ developers for C++ developers. In this episode Ankit Asthana joins Rob Irving to talk about the new features in Visual Studio 2015 that enable C++ developers to build and debug Android applications from Microsoft's popular IDE.

CppCast Episode 3: Cross Platform Mobile C++ in Visual Studio with Ankit Asthana

by Rob Irving

About the interviewee:

Ankit Asthana is a program manager working in the Visual C++ Cross-Platform space. He is knowledgeable in cross-platform technologies, compilers (dynamic and static compilation, optimizer, code generation), distributed computing and server side development. He has in the past worked for IBM and Oracle Canada as a developer building Java 7 (hotspot) and telecommunication products. Ankit back in 2008 also published a book on C++ titled C++ for Beginners to Masters which sold over a few thousand copies.

When CLion met biicode -- Anastasia Kazakova

CLion is a new cross-platform IDE from JetBrains for C and C++ developers. And Biicode is a C/C++ dependency manager. This post is about a very simple and straightforward way to use biicode features together with CLion IDE to benefit from both.

When CLion met biicode

by Anastasia Kazakova

From the article:

CMake layout for the project is generated by biicode commands, after which you can open the project directly in CLion. You can resolve dependencies and install the missing libraries easily by using bii commands from the CLion built-in terminal (Alt+F12).

Take a short overview of the overall process and some available features...

Quick Q: Return a local object rvalue reference, right or wrong?

Quick A: Wrong!

Recently on SO:

Return a local object rvalue reference,right or wrong?

I see once return a local object,the compiler will take the return value optimization.(RVO,NRVO).

The part of the Standard blessing the RVO goes on to say that if the conditions for the RVO are met, but compilers choose not to perform copy elision, the object being returned must be treated as an rvalue.


So we just write code like this:

Widget makeWidget()
{
Widget w;
…
return w;//never use std::move(w);
}

I never see somebody write code like this:

Widget&& makeWidget()
{
Widget w;
…
return std::move(w);
}

I know that returns an lvalue reference of local object is always wrong. So, returns an rvalue reference of local object is also wrong?