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 6856125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:50:43+00:00 2026-05-27T01:50:43+00:00

Clojure agents are a powerful tool. Since actions to the agents are asynchronously sent

  • 0

Clojure agents are a powerful tool. Since actions to the agents are asynchronously sent using functions “send” and “send-off”, in theory something like deadlock couldn’t happen.

Is it possible to write some Clojure code (for example invoking from some action another action to another agent) using agents in which we have some concurrency problem – it could be deadlock, race condition or anything else.

  • 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-27T01:50:44+00:00Added an answer on May 27, 2026 at 1:50 am

    send and send-off add the functions to queues for the agent and return immediately. Thus, due to their asynchronous nature, it is not possible for them to deadlock.

    However, the worker pool used by send is intended for computational work and is thus a fixed pool size (2 + # of cores). If you (incorrectly) invoke send with a task that can block for I/O or something else, that task will block one of the fixed number of cpu threads in the pool. If you did that with (2 + # of cores) tasks at the same time, you could effectively block the cpu thread pool. The solution of course is to use the correct send-off instead. The worker pool used by send-off is unbounded.

    On sending within an action, the agents page states:

    If during the function execution any other dispatches are made
    (directly or indirectly), they will be held until after the state of
    the Agent has been changed.

    When the dispatch occurs at the end of the agent, the send places the item in the send queue and returns immediately. Because agents never block waiting for a resource, there is no way to create a deadlock cycle.

    There is also no possibility for a data race – the state of an agent should be immutable Clojure data. The agent applies the change function within a send and replaces the state of the agent atomically. Readers (via dereference or @) see a stable value at some point in the agent’s lifetime. If you need coordination of readers and writers, you must use refs.

    There is a possibility of a race condition: two calls to send from different threads can “race” to be put in the queue of an agent and also concurrent readers may perceive different (stable) values depending on when they read the agent’s timeline. However, this is the nature of asynchronous computation. If you want coordinated computation when reading or writing multiple resources, you must use refs.

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

Sidebar

Related Questions

The Clojure API describes these two functions as: (send a f & args) -
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
In clojure, I can destructure a map like this: (let [{:keys [key1 key2]} {:key1
Using clojure, I've been able to successfully setup log4j very simply by using this
Since Clojure 1.3 Earmuffed Vars are No Longer Automatically Considered Dynamic, some code in
In clojure I have lines like this that define default values: (def *http-port* 8080)
In clojure, I would like to create a record inside a function. I tried:
In clojure, it is possible to destructure some keys of a map like this:
In Clojure, I would like to combine several maps into a single map where
In Clojure, I have a collection coll of 2-elements vectors. I would like to

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.