ABONAMENTE VIDEO REDACȚIA
RO
EN
Numărul 128 Numărul 127 Numărul 126 Numărul 125 Numărul 124 Numărul 123 Numărul 122 Numărul 121 Numărul 120 Numărul 119 Numărul 118 Numărul 117 Numărul 116 Numărul 115 Numărul 114 Numărul 113 Numărul 112 Numărul 111 Numărul 110 Numărul 109 Numărul 108 Numărul 107 Numărul 106 Numărul 105 Numărul 104 Numărul 103 Numărul 102 Numărul 101 Numărul 100 Numărul 99 Numărul 98 Numărul 97 Numărul 96 Numărul 95 Numărul 94 Numărul 93 Numărul 92 Numărul 91 Numărul 90 Numărul 89 Numărul 88 Numărul 87 Numărul 86 Numărul 85 Numărul 84 Numărul 83 Numărul 82 Numărul 81 Numărul 80 Numărul 79 Numărul 78 Numărul 77 Numărul 76 Numărul 75 Numărul 74 Numărul 73 Numărul 72 Numărul 71 Numărul 70 Numărul 69 Numărul 68 Numărul 67 Numărul 66 Numărul 65 Numărul 64 Numărul 63 Numărul 62 Numărul 61 Numărul 60 Numărul 59 Numărul 58 Numărul 57 Numărul 56 Numărul 55 Numărul 54 Numărul 53 Numărul 52 Numărul 51 Numărul 50 Numărul 49 Numărul 48 Numărul 47 Numărul 46 Numărul 45 Numărul 44 Numărul 43 Numărul 42 Numărul 41 Numărul 40 Numărul 39 Numărul 38 Numărul 37 Numărul 36 Numărul 35 Numărul 34 Numărul 33 Numărul 32 Numărul 31 Numărul 30 Numărul 29 Numărul 28 Numărul 27 Numărul 26 Numărul 25 Numărul 24 Numărul 23 Numărul 22 Numărul 21 Numărul 20 Numărul 19 Numărul 18 Numărul 17 Numărul 16 Numărul 15 Numărul 14 Numărul 13 Numărul 12 Numărul 11 Numărul 10 Numărul 9 Numărul 8 Numărul 7 Numărul 6 Numărul 5 Numărul 4 Numărul 3 Numărul 2 Numărul 1
×
▼ LISTĂ EDIȚII ▼
Numărul 82
Abonament PDF

C++ concurrency - Interview with Anthony Williams

Ovidiu Mățan
Fondator @ Today Software Magazine



INTERVIU

We are talking with Anthony Williams, the author of Concurrency in Action, now on Second Edition. He's passion is multithreading and for several years he was the primary developer of Boost Thread Library in C++.

You have in your book an interesting clarification / definition of the difference between parallelism and concurrency. Could you please explain this to our readers?

Anthony Williams: The difference between parallelism and concurrency is primarily a difference in focus.

When thinking about parallelism, then the focus is about making best use of the hardware to do the processing. You don't want extra threads running, because that would cause excessive switching, and you want to ensure all your cores have meaningful work to do at all times.

When thinking about concurrency, then you have a set of tasks which could potentially run at the same time, because they are mostly independent, and you are using threads to separate concerns so you don't have to handle the task switching yourself. e.g. Background spell checking. In this scenario, you might use multiple threads even on a single core machine, in order to simplify your design.

How do you prefer to approach concurrency, within multiple processes or multiple threads? Can we consider some situations where one of them is a better approach?

Anthony Williams: I usually prefer to use multiple threads rather than processes, because the communication overhead is lower: you can pass data around just by passing a pointer rather than with an expensive interprocess communication mechanism.

That said, multiple processes can be more scalable, as you can more easily run the processes on separate machines for a larger-scale network parallel computation. The enforced isolation can also lead to a safer architecture, as there is no mutable shared state.

Do you have some advices for developers to avoid deadlocks? What about mechanisms to find any potential deadlocks in the existing code?

Anthony Williams: Do not call callbacks or other external code while holding a lock.

Pay attention to the order of locks, hold locks for as short a time as possible.

Use something like thread sanitizer to detect problems.

How do you see functional programming style in C++ and do you think there is a better approach?

Anthony Williams: C++ is a multi-paradigm language, and functional style is one way to

write code. In some circumstances it is highly effective. Certainly, it helps avoid problems with shared mutable state while writing multithreaded code.

Sometimes code written in functional style is slower, or ends up more convoluted, so another style works better. It's always a trade-off.

What thread pool implementation do you regular use?

Anthony Williams: I don't have one implementation I always use. I have one for my own code which is under continual development, and I also use whatever is used by my clients: TBB, Windows thread pool, etc.

Tell us few highlights of your presentation at The Developers 2019 conference?

Anthony Williams: One of the best things that will be added to C++20 is the stop_source/stop_token/jthread package.

stop_source/stop_token make cooperative cancellation easier to manage by providing a clear signal path. jthread then integrates that into a thread wrapper, so you can easily request that the thread stop, and the thread can easily check if stopping has been requested. jthread also provides automatic request-stop-and-join on destruction, making it a "proper" RAII type. It is a better replacement for std::thread.

I also really like the new latch type. I use it all the time for testing multithreaded code.

I will also talk about coroutines, and executors, and plenty more.




LANSAREA NUMĂRULUI 129

Experts panel: JavaScript

Luni, 27 Martie, ora 18:00

sediul Accesa

Facebook Meetup StreamEvent YouTube

Conferință

VIDEO: NUMĂRULUI 128

Sponsori

  • Accenture
  • BT Code Crafters
  • Accesa
  • Bosch
  • Betfair
  • MHP
  • Connatix
  • BoatyardX
  • AboutYou
  • Telenav
  • .msg systems
  • Grab
  • Colors in projects

INTERVIURILE TSM