Solved

problem with threads

Posted on 2000-02-25
8
172 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
Industry Leaders: 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

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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