Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

design pattern za thread-safety

[es] :: C++ programiranje :: design pattern za thread-safety

[ Pregleda: 417 | Odgovora: 3 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nenadus
Belgrade

Član broj: 70488
Poruke: 20
213.137.127.*



Profil

icon design pattern za thread-safety27.10.2007. u 21:26

Da li neko zna (ili je cuo za) neki design-pattern koji istovremeno garantuje thread-safety klase i omogucava da imamo vise od jedne instance klase (dakle Singleton otpada)?

Pozdrav,
Nenad.
27.10.2007. u 21:26 

NastyBoy
Bojan Nastic
UK

Član broj: 12041
Poruke: 870
*.plus.com.

Sajt: www.frd.co.uk


Profil

icon Re: design pattern za thread-safety27.10.2007. u 21:36
To shto si naveo ispunjava svaka klasa iz, recimo, std-a (thread-safe? check. Mozhe da se instancira kad god? check), i nema tu nikakvog pattern-a.
Shta tebi tachno treba?
"The rational prisoner exploits the weak places, creates order from chaos: instead, collectives like the FSF vindicate their jailers by building cells almost compatible with the existing ones, albeit with more features."
27.10.2007. u 21:36 

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 316
*.fibertel.com.ar.



Profil

icon Re: design pattern za thread-safety28.10.2007. u 02:01
Thread safe singleton
http://www.codeproject.com/cpp/pdesingletontemplatenomfc.asp

A kao i uvek treba poceti od vikipedije:
http://en.wikipedia.org/wiki/Thread_safety

Tko leti vrijedi
28.10.2007. u 02:01 

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 2642
*.dynamic.sbb.co.yu.

Jabber: xfiles@elitesecurity.org
Sajt: www.antivari.com


Profil

icon Re: design pattern za thread-safety28.10.2007. u 08:00
Možda si mislio na RAII (a to je u suštini ono što je rekao NastyBoy u vezi STL-a) ?
("The RAII technique is often used for controlling thread locks in multi-threaded applications.")

Imaš primer za "file".


Ili, nešto slično:
--- H ---
Code:

class NEKA_KLASA
{
   // ...
   CRITICAL_SECTION LogCriticalSection;
   // ...
};

--- H ---
Code:

class CSLock
{
public:
   LPCRITICAL_SECTION fcs;

   CSLock( LPCRITICAL_SECTION acs ) : fcs( acs )
   { if ( fcs ) EnterCriticalSection( fcs ); }

   ~CSLock()
   { if ( fcs ) LeaveCriticalSection( fcs ); }
};


--- CPP ---
Code:

void NEKA_KLASA::GoSendMessageToLog( string AEvent )
{
   CSLock lock( &LogCriticalSection );
   // ...
   // ... ovde je thread safe kod
   // ...
}
NEKA_KLASA::NEKA_KLASA() // konstruktor
{
   // ...
   InitializeCriticalSection( &LogCriticalSection );
   // ...
}
NEKA_KLASA::~NEKA_KLASA() // destruktor
{
   // ...
   DeleteCriticalSection( &LogCriticalSection );
   // ...
}




[Ovu poruku je menjao X Files dana 29.04.2008. u 08:08 GMT+1]
FREEWARE
Di rečnik, v1.0.058 (srp-eng/eng-srp priručni rečnik)
http://www.antivari.com
28.10.2007. u 08:00 

[es] :: C++ programiranje :: design pattern za thread-safety

[ Pregleda: 417 | Odgovora: 3 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.