problem with threads

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 ...

Who is Participating?
MadshiConnect With a Mentor Commented:
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.
jhofbAuthor Commented:
The threads are created with CreateThread(nil, 16384, @RRunTime, Pointer(self), 0, RTThreadID);
jhofbAuthor Commented:
.. and i use delphi 5
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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
result := myobject


procedure freemyobject(i)

and in the thread you have :

amyobject := getmyobject ....

and using amyobject

you can get errors like this



What about syncronization and critical resources!
jhofbAuthor Commented:
Adjusted points to 155
jhofbAuthor Commented:
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

Thanx for the point boost...  :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.