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

  • Home
  • SEARCH
  • 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 4552334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:46:19+00:00 2026-05-21T16:46:19+00:00

ANSWER: Allright, that was quite simple (probably I made this mistake coz I need

  • 0

ANSWER:
Allright, that was quite simple (probably I made this mistake coz I need more sleep 🙂 ):
I’ve created First Thread and it created Sub-Threads and FREE-ed it-self. So it was naturall that some sub-thread souldn’t access not existing memory (before they tryed – First Thread wasn`t already in memory).

Hi,
I’m trying to make simple application.
My needs are to create for example 1-3 threads (I will call them First Threads), which will create next few threads (I will call them Sub-Threads).

I know how to do it, this is what I have done:

First Thread definition:

 type
 TFirstThread = class(TThread)
   // 
   strict private
     fID:cardinal; //fID = position on watki array + 1
     fDoneItems:cardinal;
     fItems:TSomeRecordAr;     

     //(...)
     procedure ParseItem(var item: TSomeRecord; itemID:cardinal);
   private
   public                 
   published                            
     function GetItem(itemindex:cardinal):TSomeRecord;  
     procedure SetItem(itemindex: cardinal; item: TSomeRecord);                             
     //(...)
     procedure Execute; override;
 end;

TSomeRecord is:

TSomeRecord = record
  str,str2:string;
  lst:TStrings;
  continue:boolean;
end;

Sub-Thread definition:

TSubThread = class(TThread)
  public
    fReady:boolean;
    fID,fItemID:cardinal;
    procedure Execute; override;
end;

And also array of First Threads:

watki:array of TFirstThread;

Body of First Threads:

{ TFirstThread }

//(...)

procedure TFirstThread.ParseItem(var item:TSomeRecord; itemID:cardinal);
begin
     //(...)
     with TSubThread.Create(False) do begin
       fID:=Self.fID;
       fItemID:=itemID;
       fReady:=True;
     end;
end;

procedure TFirstThread.Execute;
var
  i:cardinal;
begin
FreeOnTerminate:=True;
while fReady=False do
  Sleep(10);

//(...)
fDoneItems := 1;

for i := 0 to High(fItems) do begin
 ParseItem(fItems[i], i);
end;
// 
end;

function TFirstThread.GetItem(itemindex: cardinal): TSomeRecord;
begin
 result:=fItems[itemindex];
end;

procedure TFirstThread.SetItem(itemindex: cardinal; item: TSomeRecord);
begin
 fItems[itemindex]:=item;
end;

Body of Sub-Threads:

procedure TSubThread.Execute;
var
ftd:string;
tries:cardinal;
fItem:TSomeRecord;
begin
FreeOnTerminate:=True;
while fReady=False do
Sleep(10);
try
  //(...)
   fItem := watki[fID-1].GetItem(fItemID); //HERE AV << 
   fItem.continue:=True;
  //(...)
finally
watki[fID-1].SetItem(fItemID, fItem);
//(...)
//Free;
end;
end;

This is how doeas it looks in practice:
While I’m testing, I’m creating just 1 First Thread and start it. It has 3 items, so it creates 3 Sub-Threads.

When I make breakpoint in TFirstThread this is what I can see:

https://i.stack.imgur.com/EGaBO.jpg

everything is OK,
but after that when I make breakpoint in TSubThread this is what i get:

https://i.stack.imgur.com/gXhHW.jpg

so everithing is OK except fItems – idk why, but I can’t see it’s content. So ofc I get AV, coz item I want to get doesn’t exist.

Why can it be like that? Any solutions?

Thanks in advance.

Btw I’m using Delphi 2009

ANSWER:
Allright, that was quite simple (probably I made this mistake coz I need more sleep 🙂 ):
I’ve created First Thread and it created Sub-Threads and FREE-ed it-self. So it was naturall that some sub-thread souldn’t access not existing memory (before they tryed – First Thread wasn`t already in memory).

  • 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-21T16:46:20+00:00Added an answer on May 21, 2026 at 4:46 pm

    Allright, that was quite simple (probably I made this mistake coz I need more sleep 🙂 ): I’ve created First Thread and it created Sub-Threads and FREE-ed it-self. So it was naturall that some sub-thread souldn’t access not existing memory (before they tryed – First Thread wasn`t already in memory).

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

Sidebar

Related Questions

Alright, this is probably gonna be a pretty simple question to answer. I haven't
This answer says that Linq is targeted at a slightly different group of developers
This answer to a question about C++ unit test frameworks suggests a possibility that
In this question the answer was to flip on a switch that is picked
Alright, this one (3a; sample problem with provided answer) has got me scratching my
An answer to a Stack Overflow question stated that a particular framework violated a
In answer to this question Joel Coehoorn said Finally, only after the site's gone
This has been asked before (question no. 308581) , but that particular question and
This answer on a question on SO says ... you can read a LONG
This answer to what looks like the same question: Convert integer to hex and

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.