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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:44:11+00:00 2026-05-17T16:44:11+00:00

so far I thought that any operation done on shared object (common for multiple

  • 0

so far I thought that any operation done on “shared” object (common for multiple threads) must be protected with “synchronize”, no matter what. Apparently, I was wrong – in the code I’m studying recently there are plenty of classes (thread-safe ones, as the Author claims) and only one of them uses Critical Section for almost every method.

How do I find what parts / methods of my code needs to be protected with CriticalSection (or any other method) and which not?

So far I haven’t stumbled upon any interesting explanation / article / blog note, all google results are:

a) examples of synchronization between thread and the GUI. From simple progressbar to most complex, but still the lesson is obvious: each time you access / modify the property of GUI component, do that in “Synchronize”. But nothing more.

b) articles explaining Critical Sections, Mutexes etc. Just a different approaches of protection/synchronization.

c) Examples of very very simple thread-safe classes (thread safe stack or list) – they all do the same – implement lock / unlock methods which do enter/leave critical section and return the actual stack/list pointer on locking.

Now I’m looking for explanation which parts of code should be protected.

could be in form of code 😉 but please don’t provide me with one more “using Synchronize to update progressbar” … 😉

thank you!

  • 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-17T16:44:11+00:00Added an answer on May 17, 2026 at 4:44 pm

    You are asking for specific answers to a very general question.

    Basically, apart of UI operations, you should protect every shared memory/resource access to avoid two potentially competing threads to:

    • read inconsistent memory
    • write memory at the same time
    • try to use the same resource at the same time from more than one thread… until the resource is thread-safe.

    Generally, I consider any other operation thread safe, including operations that access not shared memory or not shared objects.

    For example, consider this object:

    type
      TThrdExample = class
      private
        FValue: Integer;
      public
        procedure Inc;
        procedure Dec;
        function Value: Integer;
        procedure ThreadInc;
        procedure ThreadDec;
        function ThreadValue: Integer;
      end;
    
    ThreadVar
      ThreadValue: Integer;
    

    Inc, Dec and Value are methods which operate over FValue field. The methods are not thread safe until you protect them with some synchronization mechanism. It can be a MultipleReaderExclusiveWriterSinchronizer for Value function and CriticalSection for Inc and Dec methods.

    ThreadInc and ThreadDec methods operate over ThreadValue variable, which is defined as ThreadVar, so I consider it ThreadSafe because the memory they access is not shared between threads… each call from different thread will access different memory address.

    If you know that, by design, a class should be used only in one thread or inside other synchronization mechanisms, you’re free to consider that thread safe by design.

    If you want more specific answers, I suggest you try with a more specific question.

    Best regards.

    EDIT: Maybe someone say the integer fields is a bad example because you can consider integer operations atomic on Intel/Windows thus is not needed to protect it… but I hope you get the idea.

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

Sidebar

Related Questions

How do I fix this code so that 1.1 + 2.2 == 3.3? What
I have a strange problem, I have a logout link that displays only if
OK, this feels like a question that should be easy to answer, but as
I have just done some tests and i have manged to get ReadAsDataContract working
I am writing an application that requires accurate timing. After asking this question ,
Good day, I'm new to selenium and I'm trying to write a simple test.
I don't know what changed in the past--this used to work: Accessing a URL
I'm am designing my database/domain for an eCommerce application and I'm having a hard
I am attempting to enumerate the set of all pairs made of elements from

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.