Przejdź do treści
Logo

kuling.pl

  • Główna
  • Arkdisk
  • Forum
  • Kontakt

Jesteś tutaj

Start » Blogi » Blog użytkownika Kuling

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

published by Kuling on wt., 2009-04-28 18:28

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

Cytat:
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

Cytat:
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

Cytat:
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.
Kategorie: 
C++
Concurrency
Programowanie
  • Blog
  • 229 odsłon

Odpowiedz

Zawartość pola nie będzie udostępniana publicznie.

WIęcej informacji o formatach tekstu

Uproszczony HTML

  • Możesz użyć w tekście znaczników BBCode. Adresy zostaną automatycznie zamienione na linki.
  • Dozwolone znaczniki HTML: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Adresy internetowe są automatycznie zamieniane w odnośniki, które można kliknąć.

Plain text

  • Możesz użyć w tekście znaczników BBCode. Adresy zostaną automatycznie zamienione na linki.
  • Znaczniki HTML niedozwolone.
  • Adresy internetowe są automatycznie zamieniane w odnośniki, które można kliknąć.
  • Znaki końca linii i akapitu dodawane są automatycznie.

Archiwum

  • Kwiecień 2012 (1)
  • Marzec 2012 (1)
  • luty 2012 (1)
  • Styczeń 2012 (7)
  • Grudzień 2011 (2)
  • Listopad 2011 (2)
  • Październik 2011 (2)
  • Wrzesień 2011 (3)
  • Sierpień 2011 (2)
  • Lipiec 2011 (3)
  • Czerwiec 2011 (1)
  • Kwiecień 2011 (4)
  • luty 2011 (1)
  • Styczeń 2011 (2)
  • Listopad 2010 (6)
  • Październik 2010 (5)
  • Sierpień 2010 (10)
  • Lipiec 2010 (3)
  • Czerwiec 2010 (2)
  • Maj 2010 (1)
  • Kwiecień 2010 (2)
  • luty 2010 (4)
  • Styczeń 2010 (5)
  • Grudzień 2009 (5)
  • Listopad 2009 (1)
  • Październik 2009 (4)
  • Wrzesień 2009 (6)
  • Sierpień 2009 (11)
  • Lipiec 2009 (23)
  • Czerwiec 2009 (14)
  • Maj 2009 (23)
  • Kwiecień 2009 (22)
  • Marzec 2009 (14)
  • luty 2009 (20)
  • Styczeń 2009 (14)
  • Grudzień 2008 (17)
  • Listopad 2008 (12)
  • Październik 2008 (10)
  • Wrzesień 2008 (4)
  • Lipiec 2008 (2)
  • Czerwiec 2008 (5)
  • Maj 2008 (5)
  • Kwiecień 2008 (9)
  • Marzec 2008 (9)
  • luty 2008 (30)
  • Styczeń 2008 (22)
  • Grudzień 2007 (15)
  • Listopad 2007 (19)
  • Październik 2007 (10)
  • Wrzesień 2007 (22)
  • Sierpień 2007 (21)
  • Lipiec 2007 (29)
  • Czerwiec 2007 (53)
  • Maj 2007 (61)
  • Kwiecień 2007 (14)
  • Marzec 2007 (5)
  • luty 2007 (4)
  • Styczeń 2007 (16)
  • Grudzień 2006 (69)
  • Listopad 2006 (15)
  • Wrzesień 2006 (25)
  • Sierpień 2006 (20)
  • Lipiec 2006 (10)
  • Czerwiec 2006 (10)
  • Maj 2006 (35)
  • Kwiecień 2006 (5)
  • Marzec 2006 (15)
  • luty 2006 (5)
  • Grudzień 2005 (10)
  • Listopad 2005 (15)
  • Sierpień 2005 (10)
  • Lipiec 2005 (20)
  • Czerwiec 2005 (30)
  • Maj 2005 (30)
  • Kwiecień 2005 (34)
  • Marzec 2005 (14)
  • luty 2005 (10)
  • Grudzień 2004 (30)
  • Listopad 2004 (48)
  • Październik 2004 (25)
  • Sierpień 2004 (18)
  • Lipiec 2004 (30)

Kategorie

  • Angielski (1)
    • FCE (0)
  • Dom (4)
    • Akwarium (3)
    • Kot (2)
  • Gry (11)
    • Counter Strike (8)
  • Informatyka (15)
    • Hardware (15)
      • Mój komputer (14)
    • Linux (0)
    • Programowanie (175)
      • C++ (134)
        • Concurrency (66)
        • Exceptions (14)
        • Templates (21)
      • Narzędzia (10)
        • Visual Studio 2003 (21)
        • Visual Studio 2005 (45)
        • Visual Studio 2008 (33)
        • Visual Studio 2010 (13)
      • PHP (9)
    • Windows (18)
  • Internet (10)
    • Drupal (18)
    • Linki (29)
  • Miejsca (2)
    • Poznań (3)
    • Sieradz (1)
    • Wrocław (12)
    • Zgorzelec (0)
  • Pieniądze (122)
    • Giełda (47)
    • Inwestowanie (66)
    • Mieszkanie (69)
  • Rodzina (14)
    • Magda (1)
  • Rozrywka (66)

Logowanie

  • Utwórz nowe konto
  • Prześlij nowe hasło
Theme provided by Danetsoft under GPL license from Danang Probo Sayekti