?
Solved

problem with threads

Posted on 2000-02-25
8
Medium Priority
?
173 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
Technology Partners: 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 620 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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