🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308999

Re: Wektory i mapy bezpieczne wątkowo

#308999
From: Matt D.
Date: Wed, 25 Jan 2017 11:25
53 lines
3315 bytes
On 1/24/2017 14:15, Borneq wrote:
> W dniu 24.01.2017 o 13:47, godek.maciek@gmail.com pisze:
>> W dniu wtorek, 24 stycznia 2017 13:40:08 UTC+1 użytkownik Borneq napisał:
>>> W wątku chcę wypełniać, w pętli w głównym czytać i kasować. Czy vector i
>>> map są bezpieczne wątkowo?
>>
>> Nie
> A co zamiast nich można użyć? A może użyć te struktury, tylko dostęp
> poprzez jakiś mutex?

Mozesz przyjrzec sie Intel Threading Building Blocks (TBB; licencja 
Apache 2.0) -- posiada concurrent container classes:
https://github.com/01org/tbb
https://www.threadingbuildingblocks.org/

Uwaga: Nie nalezy sie spodziewac cudow / darmowego lunchu (dotyczy to 
tym bardziej standardowych kontenerow recznie opakowanych mutexami -- 
t.j., "a serial container with a lock around it" bedzie jeszcze bardziej 
kosztowny i moze Ci zserializowac aplikacje, brutalnie mordujac wszelkie 
potencjalne zyski z wielowatkowosci; ale nawet lock-free nie jest za 
darmo, CPU i cache i tak musza synchronizowac dostepy do pewnego stopnia 
dla poprawnosci, a synchronizacja kosztuje):

"Notice that highly-concurrent containers come at a cost. They typically 
have higher overheads than regular STL containers. Operations on 
highly-concurrent containers may take longer than for STL containers. 
Therefore, use highly-concurrent containers when the speedup from the 
additional concurrency that they enable outweighs their slower 
sequential performance."

Tutaj masz containers:
https://software.intel.com/en-us/node/506169
https://software.intel.com/en-us/node/506079

concurrent_vector:	
https://software.intel.com/en-us/node/506203
https://www.threadingbuildingblocks.org/docs/doxygen/a00046.html

Roznice w por. z std::vector: 
http://www.randomprogramming.com/2014/08/stdvector-vs-tbbconcurrent_vector-api-design/

Patrz tez:
https://software.intel.com/en-us/blogs/2008/07/24/tbbconcurrent_vector-secrets-of-memory-organization
https://software.intel.com/en-us/blogs/2009/04/09/delusion-of-tbbconcurrent_vectors-size-or-3-ways-to-traverse-in-parallel-correctly

concurrent_hash_map:
https://software.intel.com/en-us/node/506191

concurrent_unordered_map:
https://software.intel.com/en-us/node/506171

Pozdrawiam,
Matt
Technical Details
Message-ID: <o6a208$bmh$1@portraits.wsisiz.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!.POSTED.d40a9d0a.rev.stofanet.dk!not-for-mail
References: <o67hv8$s16$1@node2.news.atman.pl> <27de4961-6dec-47f9-8846-f6b1ba2ac7c9@googlegroups.com> <o67k0q$tqa$1@node2.news.atman.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!.POSTED.d40a9d0a.rev.stofanet.dk!not-for-mail
From: "Matt D." <no-spam@invalid.local>
Newsgroups: pl.comp.lang.c
Subject: Re: Wektory i mapy bezpieczne wątkowo
Date: Wed, 25 Jan 2017 12:25:53 +0100
Organization: http://www.wit.edu.pl
Sender: mdziubin@nospam.wsisiz.edu.pl
Message-ID: <o6a208$bmh$1@portraits.wsisiz.edu.pl>
References: <o67hv8$s16$1@node2.news.atman.pl> <27de4961-6dec-47f9-8846-f6b1ba2ac7c9@googlegroups.com> <o67k0q$tqa$1@node2.news.atman.pl>
Mime-Version: 1.0
Injection-Date: Wed, 25 Jan 2017 11:26:00 +0000 (UTC)
Injection-Info: portraits.wsisiz.edu.pl; posting-host="d40a9d0a.rev.stofanet.dk:212.10.157.10"; logging-data="11985"; mail-complaints-to="abuse@wsisiz.edu.pl"
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
In-Reply-To: <o67k0q$tqa$1@node2.news.atman.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit