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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:23:05+00:00 2026-06-14T23:23:05+00:00

This may seem a little crazy, but it’s an approach I’m considering as part

  • 0

This may seem a little crazy, but it’s an approach I’m considering as part of a larger library, if I can be reasonably certain that it’s not going to cause weird behavior.

The approach:

Run async user code with a SynchronizationContext that dispatches to a thread pool. The user code would look something like:

async void DoSomething()
{
    int someState = 2;
    await DoSomethingAsync();
    someState = 4;
    await DoSomethingElseAsync();
    // someState guaranteed to be 4?
}

I’m not certain whether access to someState would be threadsafe. While the code would run in one “thread” such that the operations are, in fact, totally ordered, it could still be split across multiple threads beneath the hood. If my understanding is correct, ordering ought to be safe on x86, and since the variable isn’t shared I won’t need to worry about compiler optimizations and so on.

More importantly though, I’m concerned as to whether this will be guaranteed thread-safe under the ECMA or CLR memory models.

I’m fairly certain I’ll need to insert a memory barrier before executing a queued piece of work, but I’m not totally confident in my reasoning here (or that this approach might be unworkable for entirely separate reasons).

  • 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-06-14T23:23:07+00:00Added an answer on June 14, 2026 at 11:23 pm

    This is answered in the comments section of the async / await FAQ:

    TPL includes the appropriate barriers when tasks are queued and at the beginning/end of task execution so that values are appropriately made visible.

    So no explicit barriers are necessary.

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

Sidebar

Related Questions

This may seem a bit crazy, but if you can tell me a better
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This may seem stupid, but I can't see the events list on the Debug
this may seem a little odd, but it would make for a convenient way
This may seem a little upside down faced, but what I want to be
This may seem like a rudimentary request, but I can't seem to get it
This question may seem a little odd/weird, but I have two UIWebViews, one of
This may seem like a nit-picky detail, but I am wanting to disable to
this may seem like a simple problem but I couldn't find it in the
This may seem like a no-brainier, but the thing is I wont know the

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.