concurrency considerations around Map.clear()

Mark Price <Mark.Price@...>

I'm just starting to play around with BCC and am having trouble understanding what operations on Maps are 'safe' to perform from a python script.

Considering the example [1], my understanding is that the 'dist' histogram is written to by potentially multiple threads (i.e. whenever user or kernel code calls strlen()). Presumably there is some serialisation mechanism in place to prevent lost updates - are the bcc data structures aggregated per-cpu?

The python program then reads data from the 'dist' histogram, before calling the clear() function.

It appears that there is a race condition between reading the histogram and calling clear():

1. python program reads data & displays output
2. some kernel or user thread invokes strlen(), entry is added to the histogram
3. python program calls clear() on histogram

My question is whether the value written in (2) will be lost? In general, are concurrent operations on these data structures safe?




LMAX Exchange, Yellow Building, 1A Nicholas Road, London W11 4AN

Recognised by the most prestigious business and technology awards

2016 Best Trading & Execution, HFM US Technology Awards
2016, 2015, 2014, 2013 Best FX Trading Venue - ECN/MTF, WSL Institutional Trading Awards

2015 Winner, Deloitte UK Technology Fast 50
2015, 2014, 2013, One of the UK's fastest growing technology firms, The Sunday Times Tech Track 100
2015 Winner, Deloitte EMEA Technology Fast 500
2015, 2014, 2013 Best Margin Sector Platform, Profit & Loss Readers' Choice Awards


FX and CFDs are leveraged products that can result in losses exceeding your deposit. They are not suitable for everyone so please ensure you fully understand the risks involved.

This message and its attachments are confidential, may not be disclosed or used by any person other than the addressee and are intended only for the named recipient(s). This message is not intended for any recipient(s) who based on their nationality, place of business, domicile or for any other reason, is/are subject to local laws or regulations which prohibit the provision of such products and services. This message is subject to the following terms (, if you cannot access these, please notify us by replying to this email and we will send you the terms. If you are not the intended recipient, please notify the sender immediately and delete any copies of this message.

LMAX Exchange is the trading name of LMAX Limited. LMAX Limited operates a multilateral trading facility. LMAX Limited is authorised and regulated by the Financial Conduct Authority (firm registration number 509778) and is a company registered in England and Wales (number 6505809).

LMAX Hong Kong Limited is a wholly-owned subsidiary of LMAX Limited. LMAX Hong Kong is licensed by the Securities and Futures Commission in Hong Kong to conduct Type 3 (leveraged foreign exchange trading) regulated activity with CE Number BDV088.