Bookstore

Recent

Author Topic: TThread on Windows Mobile  (Read 4893 times)

Jaca

  • Newbie
  • Posts: 3
TThread on Windows Mobile
« on: April 30, 2011, 09:35:57 pm »
Hi !

At first I would like to sorry for my english :).

I've a problem with TThread on my Windows Mobile application:

1. Application gets GIS data from memory card to array of record type structure, analyze and display on TImage
2. Without Create the TTread it works fast (map refresh = max 100 ms)
3. When I create simple TThread (only Execute with nothing to do. Suspended or not does not matter) then application slows down (map refresh = max 4000 ms !).
4. Terminate and release (FreeAndNil(SimpleThread)) of the TThread while application is running does not help (map refresh same as in point 3)

I've tested on FPC2.4.2 and on latest snapshot. The slowdown occurs in the analysis of array, not in display of lines, polylines, points. What is wrong ?

Best regards...
Jacek

Jaca

  • Newbie
  • Posts: 3
Re: TThread on Windows Mobile
« Reply #1 on: May 02, 2011, 01:51:42 pm »
Hi again

The results of my investigation: :)

1.
Code: [Select]
Test:=BeginThread(nil,0,@ThreadProcedure,nil,0,id);Slows down the refresh of GIS map

2.
Code: [Select]
Test:=CreateThread(nil,0,@ThreadProcedure,nil,0,id);Refresh works quickly (as it should), but...:

- CreateThread() can't be used in OnCreate, OnShow.
- Synchronize - ...

Best regards...
Jacek

Laksen

  • Hero Member
  • *****
  • Posts: 639
    • J-Software
Re: TThread on Windows Mobile
« Reply #2 on: May 02, 2011, 05:48:07 pm »
The difference between BeginThread and CreateThread, is that BeginThread will initialize the heap manager for multithreaded operation. If this isn't done then exception handling and proper locking of the heap (probably) isn't done

CreateThread on the other hand will not notify the thread code of the FPC RTL.

In my opinion it sounds like a symptom. If there's so large a difference then you probably have something in the update code that could be made a whole lot more efficient, ex. avoid exceptions, strings and just overall memory allocation. Those are the only things I can imagine that can actually change the performance when going from a singlethreaded to a multithreaded RTL

Jaca

  • Newbie
  • Posts: 3
Re: TThread on Windows Mobile
« Reply #3 on: May 02, 2011, 08:38:57 pm »
Laksen, now I try to use the CreateThread() to handle the TCP connections (I'm testing now). I'll not use TThread class or BeginThread due to their delay.

I've noticed that I can't use a try...except...end in the ThreadProcedure of CreateThread(). The application (with try...except...end) works in the emulator but in HTC HD2 doesn't work. :) The HTC HD2 executes ThreadProcedure only once and the application is terminate without any event.

Jacek

Laksen

  • Hero Member
  • *****
  • Posts: 639
    • J-Software
Re: TThread on Windows Mobile
« Reply #4 on: May 02, 2011, 08:48:32 pm »
Please provide some code of what you're trying to do

As I said, exceptions won't work if you don't use BeginThread or TThread. This functionality uses threadvars, which are only initialized by BeginThread. Any use of memory allocation will probably make the program crash in the long run if you use CreateThread, because the heapmanager might not be noticed that it has to be threadsafe. This of course makes the program incur a small penalty because of locking, but not anything that should make the program have that large delays