Test się skończy, stres – zostanie?

http://blogi.bossa.pl/?p=955

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?


http://www.lenholgate.com/archives/000449.html
http://blogs.codehaus.org/people/jboner/archives/001135_use_total_ordering_of_objects_to_avoid_deadlocks.html


 --


I jeszcze trochę na temach hierarchii:
http://www.onjava.com/pub/a/onjava/2004/10/20/threads2.html?page=1


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:
http://msdn.microsoft.com/en-us/magazine/cc163618.aspx

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ę:
http://www.justsoftwaresolutions.co.uk/threading/acquiring-multiple-locks-without-deadlock.html

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

http://www.lenholgate.com/archives/000824.html

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ę. :)


http://www.imf.org/external/pubs/ft/gfsr/2009/01/pdf/text.pdf


http://www.rybinski.eu/?p=720&language=pl

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?


http://msdn.microsoft.com/en-us/magazine/cc188951.aspx

C++ FAQ Lite - Exceptions and error handling

http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.11

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
- RAII
- try / catch mess
http://www.ddj.com/cpp/184403758

Create a Language Compiler for the .NET Framework

http://msdn.microsoft.com/en-us/magazine/cc136756.aspx

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

http://www.trystero.pl/archives/2992


 

Baltic Dry Index

http://zezorro.blogspot.com/2009/04/do-contanga-trzeba-dwojga.html


http://en.wikipedia.org/wiki/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.


http://ftalphaville.ft.com/blog/2009/04/20/54845/tanked/?source=rss


http://www.naftemporiki.gr/markets/quotegraph.asp?id=.BADI&ctime=5Y&cperiodicity=D&cstyle=L

Perspektywy amerykańskiego dolara

http://wojciechbialek.blox.pl/2009/04/Perspektywy-amerykanskiego-dolara-1.html

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.


http://www.secretgeek.net/open_code_sharing.asp

Use Thread Pools Correctly: Keep Tasks Short and Nonblocking

http://www.ddj.com/go-parallel/article/showArticle.jhtml?articleID=216500409

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

http://www.simplehelp.net/2006/09/27/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.


http://msdn.microsoft.com/pl-pl/magazine/cc817398(en-us).aspx

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.


http://en.wikipedia.org/wiki/Lock_convoy

.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.


http://msdn.microsoft.com/en-us/magazine/cc872851.aspx

DebuggerVisualizer

http://pawlos.blogspot.com/2009/04/debuggervisualizer.html

__try/__except - jak złapać EXCEPTION_ACCESS_VIOLATION

http://msdn.microsoft.com/en-us/library/swezty51(VS.80).aspx



int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
{
if (code == EXCEPTION_ACCESS_VIOLATION)
{
return EXCEPTION_EXECUTE_HANDLER;
}
else
{
return EXCEPTION_CONTINUE_SEARCH;
};
}

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

Unhandled exceptions - _set_se_translator and /EHa

_set_se_translator
http://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx


/EHa
http://msdn.microsoft.com/en-us/library/1deeycx5(VS.80).aspx


EXCEPTION_ACCESS_VIOLATION
http://msdn.microsoft.com/en-us/library/ms679356(VS.85).aspx


Structured Exception Handling (C++)
http://msdn.microsoft.com/en-us/library/swezty51(VS.80).aspx


 

Unhandled C++ Exceptions - set_terminate

http://msdn.microsoft.com/en-us/library/ac9f67ah(VS.80).aspx


 

 
Tomasz Kulig