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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:45:48+00:00 2026-05-21T22:45:48+00:00

I have a multi-threaded Delphi program creating multiple instance of some classes, and I

  • 0

I have a multi-threaded Delphi program creating multiple instance of some classes, and I want each class instance to have its own instance of TMultiReadExclusiveWriteSynchronizer for use in the get and set methods of specific properties.

E.g. Here’s part of a unit where I’m using a TMultiReadExclusiveWriteSynchronizer in one class:

interface

TSGThread=class(TThread)
private
    fWaiting:boolean;
    function getWaiting:boolean;
    procedure setWaiting(value:boolean);
public
    property waiting:boolean read getWaiting write setWaiting;
end;

implementation

var syncWaiting:TMultiReadExclusiveWriteSynchronizer;

function TSGThread.getWaiting:boolean;
begin
    syncWaiting.BeginRead;
    result:=fWaiting;
    syncWaiting.EndRead;
end;

procedure TSGThread.setWaiting(value:boolean);
begin
    syncWaiting.BeginWrite;
    fWaiting:=value;
    syncWaiting.EndWrite;
end;

initialization
    syncWaiting:=TMultiReadExclusiveWriteSynchronizer.Create;
finalization
    syncWaiting.Free;
end.

The problem with this is that the unit creates one instance of TMultiReadExclusiveWriteSynchronizer which is then used by multiple instances of TSGThread.
The synchronizer is only controlling access to a private field of TSGThread.
Thread A could modify the field in Thread B using the public property, hence the need for the synchronizer, but there should be a separate synchronizer in each thread so the threads don’t have to wait on each other if they’re modifying their own properties.

Delphi Help says “create a global instance of TMultiReadExclusiveWriteSynchronizer”, but is it strictly necessary for it to always be global?
If a class is only protecting access to its own properties, will the synchronization work with a TMultiReadExclusiveWriteSynchronizer instance in a private field?

  • 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-21T22:45:48+00:00Added an answer on May 21, 2026 at 10:45 pm

    It’s not strictly necessary for it to be global. It is necessary for the every access to go through the synchronizer in order to maintain thread safety. One easy way to enable that is by making the synchronizer a global variable, but there are other ways to handle it.

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

Sidebar

Related Questions

I have a multi-threaded Cocoa app that processes images. The program has a progress
I have a multi threaded wpf application with various HW interfaces. I want to
suppose we have multi processor machine and multi threaded application. If two threads have
I have a multi-threaded app which is running under Linux 2.6.30 on an 8
I have a multi-threaded application that has a centrlaised list that is updated (written
I have a multi threaded application that writes to a settings xml file using
I have a multi-threaded application which scales well to begin with, but running on
I have a multi-threaded script which occasionally freezes when it connects to a server
I am totally new to programming and I have chosen Delphi as the programming
I've got a multithreaded app using the OmniThreadLibrary . I am misusing the OTL

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.