Test się skończy, stres – zostanie?


Kolejność synchronizowania według kolejności adresów w pamięci?

Jak wiadomo dead-locki (najczęstsze) powstają w następujacych sytacjach:

  • mamy dwa (conajmniej) obiekty synchronizujace S1, S2

  • wątek T1 zawłaszcza obiekty w kolejności S1, S2

  • wątek T2 zawłaszcza obiekty w kolejności S2, S1

  • oba wątki wykonują się w tym samym czasie

Jakiś czas temu wklejałem link do artykułu gdzie zalecano hierachię (globalną hierarchię) wszystkich sekcji krytycznych tak aby unikać dead-locków. http://www.ddj.com/hpc-high-performance-computing/204801163?pgno=3

Dziś znalazłem całkiem ciekawy sposób ustalania globalnej hierachii.

Można brać sekcje w kolejności rosnących fizycznych adresów w pamięci. :) Fajne, czyż nie?



I jeszcze trochę na temach hierarchii:

The most practical rule to avoid deadlock is to make sure that the locks are always acquired in the same order. In our example, it means that either the score or character lock must be acquired first—it doesn't matter which as long as we are consistent. This implies the need for a lock hierarchy—meaning that locks are not only protecting their individual items but are also keeping an order to the items. The score lock protects not only the values of the score, but the character lock as well.


I jeszcze troche na temat poziomów:

While lock leveling works, it does not come without challenges. Dynamic composition of software components can lead to unexpected runtime failures. If a low-level component holds a lock and makes a virtual method call against a user-supplied object, and that user object then attempts to acquire a lock at a higher level, a lock hierarchy-violation exception will be generated. A deadlock won't occur, but a run-time failure will. This is one reason that making virtual method calls while holding a lock is generally considered a bad practice. Although this is still better than running the risk of a deadlock, this is a primary reason databases do not employ this technique: they must enable entirely dynamic composition of user transactions.


I jeszcze trochę:

The easiest way to deal with this is to always lock the mutexes in the same order. This is especially easy if the order can be hard-coded, and some uses naturally lend themselves towards this choice. For example, if the mutexes protect objects with different roles, it is relatively easy to always lock the mutex protecting one set of data before locking the other one. In such a situation, Lock hierarchies can be used to enforce the ordering — with a lock hierarchy, a thread cannot acquire a lock on a mutex with a higher hierarchy level than any mutexes currently locked by that thread.

MSVC, STL, locale and thread-unfriendly object


Aktualnie czytam - More Exceptional C++ Herb Sutter

try/catch in constructor

Morals About Safe Coding

Moral #4: Always perform unmanaged resource acquisition in the constructor body, never in initializer lists. In other words, either use "resource acquisition is initialization" (thereby avoiding unmanaged resources entirely) or else perform the resource acquisition in the constructor body.

Moral #5: Always clean up unmanaged resource acquisition in local try block handlers within the constructor or destructor body, never in constructor or destructor function try block handlers.

Moral #8: Prefer using "resource acquisition is initialization" to manage resources. Really, really, really. It will save you more headaches than you can probably imagine, including hard-to-see ones, similar to some we've already dissected.

More Exceptional C++, Herb Sutter


IMF Global Financial Stability Report - April 2009

Strasznie dużo czytania. Samo przejrzenie obrazków zajeło mi ponad godzinę. :)



typename keyword versus class keyword

Can you explain the purpose of the typename keyword in C++? When should I use it instead of <class T>? Is there some difference between the two?


C++ FAQ Lite - Exceptions and error handling


Exception safe code in real world

Below you can find three methods of writing exception safe code in real world. In the order prefered by author:

- Petru's ScopeGuard
- try / catch mess

Create a Language Compiler for the .NET Framework


Co oznacza powrót Amerykanów do oszczędzania?



Baltic Dry Index



On the world’s largest VLCC trading route, from the Middle East to Japan, rates have fallen to under $8,000 per day, just over 10% of the $70,000 per day seen at the beginning of 2009.   “There’s no reason why the market should be where it is,” said Frontline acting chief executive Jens Martin Jensen.   “It doesn’t make any sense. If [a crude oil trader] pays $50 a barrel and you have 2m barrels on board [a tanker] worth $100m, who cares if you are paying $10,000 or $20,000 per day? It doesn’t make any difference. It’s weakness in certain owners minds.



Perspektywy amerykańskiego dolara


Bambrick's 8th Rule of Code Reuse

It's far easier and much less trouble to find and use a bug-ridden, poorly implemented snippet of code written by a 13 year old blogger on the other side of the world, than it is to find and use the equivalent piece of code, written by your team leader on the other side of a cubicle partition.


Use Thread Pools Correctly: Keep Tasks Short and Nonblocking


How to use your PC and Webcam as a motion-detecting and recording security camera


Lock Convoys

When the arrival rate at a lock is consistently high compared to its lock acquisition rate, a lock convoy may result. In the extreme, there are more threads waiting at a lock than can be serviced, leading to a catastrophe. This is more common on server-side programs where certain locks protecting data structures needed by most clients can get unusually hot.


Critical sections as implemented in Microsoft Windows operating systems provide a good example of how lock convoys can occur. In Windows, critical sections use a combination of a spinlock and a kernel synchronization object called an "event" to ensure mutual exclusion. For low-contention critical sections, the spinlock will provide mutual exclusion most of the time, falling back on the event only when a thread fails to acquire the spinlock within a certain amount of time. When contention is high, however, it is possible for many threads to fail to acquire the spinlock and enter a waiting state, all waiting on the same event.


.NET Matters: False Sharing

As one example, the code in Figure 4 shows a version of this code that doesn't suffer from the same problem. Instead, it allocates a bunch of extra Random instances between those that we care about, thus ensuring that the ones we do care about are far enough apart so as to not be subject to false sharing (at least on this machine). For our tests, this updated version produced significantly better results, running up to six times faster than the code from Figure 3 on our dual-core test machine.




__try/__except - jak złapać EXCEPTION_ACCESS_VIOLATION


int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)

void test()
*((char *)(NULL)) = 2;
__except(filter(GetExceptionCode(), GetExceptionInformation()))
cout << "wicked :)";

Unhandled exceptions - _set_se_translator and /EHa




Structured Exception Handling (C++)


Unhandled C++ Exceptions - set_terminate



Tomasz Kulig