Solved

problem with threads

Posted on 2000-02-25
8
171 Views
Last Modified: 2010-04-04
i´ve the following problem : i've a multithread application and when i start only one thread (the other thread is waiting for an event) it works fine. But when the second thread (or some more) is also running, i get an error which i can't locate. How can i fix this error ? The threads are created with CreateProcess from which a Class-method is called.
I get one of these two errors's :
PROJEKT WT2K.EXE raised Exceptionclass EInvalidPointer with message "Invalid Pointer Operation". Prozess stoped. Press step or run.
PROJEKT WT2K.EXE faulted with Message "Accessviolation at 0x00401d01 write of adress 0x001 process stopped ...

0
Comment
Question by:jhofb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:jhofb
ID: 2560140
The threads are created with CreateThread(nil, 16384, @RRunTime, Pointer(self), 0, RTThreadID);
0
 

Author Comment

by:jhofb
ID: 2560144
.. and i use delphi 5
0
 
LVL 4

Expert Comment

by:mhervais
ID: 2560438
Hi jhofb

Can you send some sample code ?

why don't you use the vcl TThread class ?

Your looks like problem looks like you are not protecting common resources as tightly as you think :

for instance lets say that you have something like this

function getmyobject(i) : tmyobject
....
criticalsection.enter
result := myobject
criticalsection.leave

and

procedure freemyobject(i)
....
criticalsection.enter
.....
myobject.free
criticalsection.leave

and in the thread you have :

amyobject := getmyobject ....

and using amyobject

you can get errors like this

HTH

Marc

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Motaz
ID: 2560501
What about syncronization and critical resources!
0
 
LVL 20

Accepted Solution

by:
Madshi earned 155 total points
ID: 2560526
Set the variable "IsMultiThread := true". If you don't do that, Delphi's memory manager is not thread safe. The TThread VCL class does that internally, but if you call CreateThread directly you have to set the variable manually. (I've been there, too). Another thing you have to do is to protect all resources that you use in both threads with synchronization functions like critical sections, events and mutexes.

Regards, Madshi.
0
 

Author Comment

by:jhofb
ID: 2560909
Adjusted points to 155
0
 

Author Comment

by:jhofb
ID: 2560910
madshi,
thanks for this very very very very ... good answer (i`ve been searching to solve this problem for over 20h) thanks.
nearly i desired to sell my computer and get a farmer
155 all i had

0
 
LVL 20

Expert Comment

by:Madshi
ID: 2561587
Thanx for the point boost...  :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 89
Working with hours 3 85
how to update exe applicatio from internet ? 6 104
JAudiorecorder record freezing the app 29 89
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question