Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 415305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:22:04+00:00 2026-05-12T18:22:04+00:00

I read an article that claims that closures (or blocks) are a useful weapon

  • 0

I read an article that claims that closures (or “blocks”) are a useful weapon in the “War on Multicores”, because

[…] they allow you to create units of
work, which each have their own copy
of the stack, and don’t step on each
others toes as a result. What’s more,
you can pass these units around like
they are values, when in actual fact
they contain a whole stack of values
(pun intended), and executable code to
perform some operation.

Now, I am not debating the usefulness of closures in general and possibly also for concurrent programming in a shared-memory model, but what’s the difference with a thread that only acts on local data (or processes, or actors, or …)?

Isn’t a closure on its own as useful for concurrent programming as a thread without a scheduler?

What with closures that have non-local side effects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:22:05+00:00Added an answer on May 12, 2026 at 6:22 pm

    The argument is that having closures in your programming language makes it easier to have some work done in another thread. I think the author should have mentioned the importance of higher-order function in that argument.

    My favorite introduction to higher-order functions is “Why functional programming matters”, I won’t try to present a bad replica here.

    So using closures doesn’t give you parallelism for free if you’re going do execute closures in for loops, e.g.

    for (int i = 0; i < numElements; i++) {
      result[i] = closure(inputs[i], i);
    }
    

    because the language can’t tell if closure(a, b) somehow changes other values in the result or inputs arrays. But languages with higher-order functions like map specify that the function passed to map shouldn’t look at or change other values in the inputs, and prevent it from affecting other results. So, code like the following, which is common in functional languages, can be parallelized for you, without you needing to create a pool of worker threads and hand off the closure to them:

    results = map(closure, inputs, [0..numElements-1]);
    

    In these languages, closures take away the pain of declaring a new function somewhere for short pieces of code. That makes it more fun to use higher-order functions.

    The following Haskell code defines a function f that takes a list of numbers and returns a list where each input i is replaced with 2i+1. By saving you the hassle of creating a function to compute 2i+1 this is 1 line of code instead of 2.

    f nums = map (\i -> 2*i+1) nums
    

    Again, see “Why functional programming matters” for strong arguments as to how this scales up to real code bases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this [useful article] that says I can create a library of inline
I read in this article that in Java, nested synchronised blocks are allowed. I
I read in this article that a company has created a software capable of
I was wondering, I recently read an article that spoke of the ills of
Recently I read in an article that the Approach 1 following is more preferred/advantagious
I read this article on the maven project web page that lists the different
I just read this article on how to create global hotkeys using Carbon events.
Some time ago I read an article that explained several pitfalls of argument dependent
I'm trying to improve my OOP skill. Recently, I've read an article that has
I read an article stating that GPU are the future of supercomputing. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.