The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,230 other followers

Archive for the ‘Multi-Threading / Concurrency’ Category

Laptop fan profiling, and debugging them – related to Profiling | CommitStrip

Posted by jpluimers on 2019/07/23

A while back, I posted the “profiling” CommitStrip on[WayBack] Profiling – Jeroen Wiert Pluimers – Google+. Boy how did I not know that within a week, I bumped into a “laptop fan profiling” artefact.

A coworker noticed, that when starting a thread based equivalent of [WayBack] TTimer Class (which cannot be used in services as it depends on the VCL), then sometimes the laptop fans would spin up.

What basically happened was that for certain combinations of Enabled and Interval the Execute would loop burning 100% of one CPU core.

With 3 or more – sometimes 2 – of these threads active on a 4+4 core (4 are hyper-threaded), the processor fan would start to spin like madness.

Finding the solution was somewhat easy too:

  • Process Explorer would show the thread IDs burning the most CPU cycles
  • Delphi shows the Thread IDs in the Thread Status pane (if they are named, the ID is at the end of the name in parenthesis)
  • At around Delphi 2010, you can Freeze or Thaw threads. This allows you to debug only a single thread by freezing all others.

Focussing on one thread, allowed a close inspection of the loop, quickly finding the actual cause and repairing it.

TTimer Thread

A similar and better class is at [WayBack] multithreading – TTimerThread – Threaded timer class – Code Review Stack Exchange, based on [WayBack] timer – Using VCL TTimer in Delphi console application – Stack Overflow.

Read the rest of this entry »

Posted in Conference Topics, Conferences, Debugging, Delphi, Development, Event, Fun, Multi-Threading / Concurrency, Profiling-Performance-Measurement, Software Development | Leave a Comment »

Threads are not the answer | CompuTruthing

Posted by jpluimers on 2019/07/17

Long read, but worth it: [WayBack] Threads are not the answer | CompuTruthing

We argue that the thread-oriented approach to concurrency is a bad approach. It has severe modifiability problems, but also performance problems. We should not think in terms of low level primitives.

It has great analogies between threading and cars on roads:

Software world Automotive world
thread road
work unit set of cars that pass over a road in a period of time
work unit dependencies cars need to go from one road to another
total execution time total time for all cars to reach the destination
lock/semaphore traffic lights / roundabout
too few work unit dependencies (highway) road network badly connected (sometimes this means long way to nearby locations)
too many work unit dependencies too many intersections or access points (too much time spent in these)
too many small threads (descheduled often) small roads
threads that are not descheduled from cores highways

Via

[WayBack] Kevlin Henney – Google+ 

Related videos under the fold (more at DevTube – Videos by @kevlinhenney)

–jeroen

Read the rest of this entry »

Posted in Development, Multi-Threading / Concurrency, Software Development | Leave a Comment »

The red zone, is why you want immutable constructs

Posted by jpluimers on 2019/05/23

Most code I come across is in the red zone, exactly depicting why you want immutable constructs. Immutable constructs will never end-up in the red zone.

Image: [WayBackWayback Machine.

The red zone is just one quadrant on the mutability/shareability diagram and getting outside that red zone quadrant is key.

With processor cores now becoming ubiquitous: you cannot get outside of the “Shard” half, so you have to get outside of the “Mutable” half.

Explaining the why and how, is part of a few presentations that Kevlin Henney gave:

Related YouTube videos are below.

–jeroen

Read the rest of this entry »

Posted in Conference Topics, Conferences, Development, Event, Multi-Threading / Concurrency, Software Development | Leave a Comment »

ILockable/TLockable/Lockable. Similar to IManaged in Spring4D, but provides a Locked interface.

Posted by jpluimers on 2019/04/10

Had to use this to start solving threading issues in a project I inherited a while ago in a temporary way before doing a huge refactoring. Will likely need it in the future as well: ILockable/TLockable/Lockable. Similar to IManaged in Spring4D, but provides a Locked interface..

ILockable/TLockable/Lockable. Similar to IManaged(now IShared) in Spring4D, but provides a Locked interface.

Note this is very inefficient, but can be practical as a shotgun approach to start solving the mess when you inherit a project that has the “I know, I’ll use threads!” approach in it.

Replace the resource typed TNeedsLock that needs protection with a ILockable<TNeedsLock>, then route all references via a call to the Locked()() call to it.

If you need a simpler approach, then use [WayBack] Interfaced monitor lock — Bitbucket by Stefan Glienke.

–jeroen

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Development, Event, Multi-Threading / Concurrency, Software Development | Leave a Comment »

Requirements to write multi threaded code

Posted by jpluimers on 2019/04/01

Steps:

  1. get gist.github.com – Developers must be this tall to write multi threaded code
  2. render to PNG/PDF/HTML
  3. print
  4. attach to wall

Via [WayBack] Kristian Köhntopp – Google+

Related:

Bernd Paysan’s:

The three most 2. common race
1. off-by-one software conditions
errors:
counting
core dumped (Segmentation fault in printf)

–jeroen

Read the rest of this entry »

Posted in Development, Fun, Multi-Threading / Concurrency, Software Development | Leave a Comment »

 
%d bloggers like this: