Solved

Threads ....

Posted on 2001-06-17
7
268 Views
Last Modified: 2010-04-06
My Application has about 8 thereads that need to update
Grid very often.

It happend that the application stop respond.
I guess that this is because threads problem

I use every grid update with      EnterCriticalSection(CriticalSec);

My quesiton how can i detect the bug ?



0
Comment
Question by:asi
[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
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6200177
Why don't you use 'Synchronize'?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 6200557
Are you utilizing the Sychronize as: Epsylon  has suggested.  You must utilize this in order to access the VCL from a thread. Further more, 8 threads plus the initial process which is a thread itself, makes nine threads. You must make sure you have the memory resource to have that many threads. Try disabling all threads and running one at a time until you find the thread with the problem. However, I am sure the problem is in the Synchronize by the brief spec you have posted.


Shane Holmes
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6201075
Using Synchronize is only a choice if updating the grid is only a minor task of the threads. If updating the grid is the main task of the threads, then forget about Synchronize. Synchronize is a hack, that makes the main thread execute the synchronized method.

However, as already indicated by the other experts, the VCL is not thread safe. So basically you must not access VCL components in other threads than the main thread.

A solution could be to use pure win32 APIs/controls instead of VCL components. These are thread safe and so can be accessed safely by all the threads.

If you want to know why your program stopped responding exactly, I have a trick for you: Just last week I've written a little utility which hooks into a hanging/freezed Delphi application and shows the current callstack of all threads. This way you can e.g. see, that thread 2 and 3 are waiting for the critical section or something like that. In order for this utility to work, your application must have mapfiles attached with my package "madExcept". It's free for non-commercial usage and also free for any usage on your development PC. If you're interested give me your eMail address, then I'll send the utility to you. It runs under NT/2000 only, though, not under win9x...

Regards, Madshi.

http://help.madshi.net/Data/madExcept.htm
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!

 

Author Comment

by:asi
ID: 6201610
madshi
b_asi@hotmail.com

The problem is that my application only freeze and i do not get any exception , does your utility will help ?
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 6201676
As Madshi said 'Synchronize is a hack', Only last friday I had a program that was using Synchronize to run a VCL method.  But the program wasn't working.

I fixed the problem by posting a message to the form (that contains the Object) then waiting for the form to set a flag, before contining, also using the Sleep procedure to put the thread to sleep and allow the other threads to use the CPU.  This works extremly well, and I don't think that I'll bother with the Syncronize method ever again!

Colin Dawson
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
ID: 6201705
Yes, asi, to analyze a frozen process (without a raised exception) is exactly what I've written this utility for.

Regards, Madshi.
0
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6201774
 I, basicaly, like the EnterCriticalSection(); approach. It is much better than Synchronize, because it is in Windows' nature. However, a deadlock may easily occure. If you share some of your code, or at least the idea you use I may be able to help you.
  And to Shane Holmes: it is not a big overhead for Windows to hold up 9 more threads: this is what it is made for. The thread structure is not a big resource/memory user. And switching between threads is not big deal for Windows - change the state register, the stack and few other pointers and poof! - you are done. It would be much worse if it was 9 processes.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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