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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:07:08+00:00 2026-06-08T16:07:08+00:00

Let’s say I have some class, TMaster, which asa field includes a TIdTCPServer. Some

  • 0

Let’s say I have some class, TMaster, which asa field includes a TIdTCPServer. Some method of the TMaster class is responsible for the OnExecute event of the TIdTCPServer.

Firstly, is this threadsafe and acceptible? Secondly, let’s assume my class has many other private fields (Name, Date, anything…) can the OnExecute event – which is really a method INSIDE the TMaster class, write to these variables safely?

I guess I mean to ask if private fields are threadsafe in this situation?

I am really new to threading and any help will be greatly appreciated!

Thanks,
Adrian!

  • 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-08T16:07:09+00:00Added an answer on June 8, 2026 at 4:07 pm

    The way I approach this is not to have the fields used by the events belong to the TidTCPServer
    owner, but define a custom TidContext descendant and add the fields to that class.

    Then you simply set the ContextClass property on the server class to the type of the of your custom context. This way each Connection/Thread will get its own custom context containing its own private fields, this way there is no issue with concurrent thread access to the same fields.

    if you have a list of objects that need to be accessed by the different contexts you have two options.

    1) create copies the objects and store them in a private field in for each context instance
    This can be done in the OnConnect Event.

    2) Protect the objects from concurrent thread access using a synchroniser eg TIdCriticalSection, TMultiReadExclusiveWriteSynchronizer or semaphore,

    which method you use depends on each individual situation.

    if you need to manipulate any vcl components remember this can’t safely be done outside the main vcl thread therefore you should create your own tidnotify decendants for this. performing this sort of operation using tidsynch can lead to deadlocks when stoping the tidtcpserver if it is in the middle of a vclsynch operation.

    this is just some of what I have learned over the course of a few years using Indy.

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

Sidebar

Related Questions

Let's say I have a method in java, which looks up a user in
Let's say you have a class called Customer, which contains the following fields: UserName
Let me explain best with an example. Say you have node class that can
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a method that expects a numerical value as an argument.
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say you have a class, with certain properties, and that you tried your
Let's say I have two objects, Master and Slave . Slave has a method

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.