Solved

problem with threads

Posted on 2000-02-25
8
166 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
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
 
LVL 7

Expert Comment

by:Motaz
ID: 2560501
What about syncronization and critical resources!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now