Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat von »"koschka"«
In Unix gibt es z.b. das fork, welches aus einen Vater Prozess einen Kind Prozess macht, der Kind Prozess ist auser seiner ID identisch mit dem Vater (gleiche Anzahl Threads etc.) Vllt. schreibe ich mal sowas wie einen Artikel "Probleme bei Multithreading", wie schreibe ich "Critical Sections" etc. dadurch würde das Thema abgerundet sein, muss ich aber erst FlyingDragon fragen, und Zeit haben .
Sheddex
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
template <class T> class SecureList : private std::list<T> { #ifdef _WIN32 CRITICAL_SECTION Critic; #else pthread_mutex_t Critic; #endif public: #ifdef _WIN32 SecureList(void) { InitializeCriticalSection(&Critic); } ~SecureList() { DeleteCriticalSection(&Critic); } inline void lock(void) { EnterCriticalSection(&Critic); } inline void unlock(void) { LeaveCriticalSection(&Critic); } #else SecureList(void) { pthread_mutex_init(&Critic, NULL); } ~SecureList() { pthread_mutex_destroy(&Critic); } inline void lock(void) { pthread_mutex_lock(&Critic); } inline void unlock(void) { pthread_mutex_unlock(&Critic); } #endif inline std::list<T>::iterator begin(void) { lock(); return std::list<T>::begin(); } //ACHTUNG: begin führt automatisch einen lock durch inline void clear(void) { lock(); std::list<T>::clear(); unlock(); } inline std::list<T>::iterator erase(std::list<T>::iterator &it) { lock(); return std::list<T>::erase(it); unlock(); } //ACHTUNG: Liste sollte vorher gelockt sein! inline void push_back(const T e) { lock(); std::list<T>::push_back(e); unlock(); } inline void push_front(const T e) { lock(); std::list<T>::push_front(e); unlock(); } inline std::list<T>::iterator end(void) { return std::list<T>::end(); } inline size_type getSize(void) { return std::list<T>::size(); } }; |
Zitat von »"rewb0rn"«
Flying Dragon du hast oben was von einer Threadklasse geschrieben die du erstellt hast, die würde mich interessieren.
Werbeanzeige