Solved

Is it possible that multithreading wont work if my core is only 1

Posted on 2010-11-15
8
373 Views
Last Modified: 2012-05-10
hi

I've build a basic multithreading of record type via tmemorystream

type
tmythread = class(tthread)
private
MStream:TmemoryStream;
StreamRec: pmyStreamRec; //packed record type
xscore: integer;
retvalue: integer;
procedure showStatus;
protected
procedure execute; override;
constructor Create(createsuspended:boolean);
end;
...
var  mythreads: array[0..max-1] of tmythread;  
...
  mythreads[0] := tmythread.Create(true);
   mythreads[0].MStream := db.tptStream1;
   mythreads[0].StreamRec := db.StreamRec1;
   mythreads[0].Resume;

   mythreads[1] := tmythread.Create(true);
   mythreads[1].MStream := db.tptStream2;
   mythreads[1].StreamRec := db.StreamRec2;
   mythreads[1].Resume;
...

Number of seconds WITHOUT using class tthread: 12s+-
Number of seconds USING class tthread with 2 threads: 12s+-

There the same.

What if I test this on dual core or quad core?,  What possibly is the result?

What is your analysis?
0
Comment
Question by:systan
  • 4
  • 2
  • 2
8 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34142928
owch , my eyes !
where is the indenting ?

and the implementation of the threads ?
0
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 50 total points
ID: 34143037
with 1 core you can stil have 2 cpu if you switch on hyperthreading

windows assigns a fraction of time to each thread within a specific time frame
if you have 1 second of time and 10 threads and 1 core
each thread will have run 100ms (providing the thread allows the processor to switch to the next thread)
the higher the priority, the more time a thread is given

if you have 2 cores and you have set the affinity to auto or divided equally
the time is doubled for each thread

and so on for 4 cores, 8 cores, 16 cores, etc ...

0
 
LVL 14

Author Comment

by:systan
ID: 34143100
hi Geert;
I don't understand what you mean.
I have only 1 core cpu, with intel celeron 1.6hz and free memory 500mb.
my bad for not having a detail.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 25

Accepted Solution

by:
epasquier earned 75 total points
ID: 34143233
> with 1 core you can stil have 2 cpu if you switch on hyperthreading
Not all CPU have Hyperthreading. Not even all Intel CPU, only old Petiums IV , then abandonned with Intel Core architecture only to be found again with Core i7 hi-end series. Certainly not to be seen in lower-end CPU like Celeron

Well, with 1 core without hyperthreading, that means that only one thread can run at one time. If you have more than 1 thread , then the CPU will switch from one to the other like it does with process, I wouldn't count on much better performances. One thread could be put on hold while some data is coming from DB or network, and the other thread could take some gain by working during this time until it is also on hold waiting data.

It's impossible to tell you how much gain you can have without your complete implementation, and loads of informations about your DB, network, harddrive etc... Even then, only experience can tell for sure. As you have experienced already, just remember that multithreading can be WORSE than 1 thread only.
Especially if you have only one core : not only the drive/db/network is a bottleneck, but your CPU as well.
0
 
LVL 25

Expert Comment

by:epasquier
ID: 34143249
Ah, I forgot to tell : Of course a multithreaded application will work on 1 Core machine.
But as I said, get some gains from that is another story
0
 
LVL 14

Author Closing Comment

by:systan
ID: 34143635
Thanks
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34143669
systan,
you are lacking the knowledge about the ins and outs of multithreading
as you don't get the basics you won't be able to grasp the answers
> finding the bottlenecks
> protecting the shared resources
> synchronizing multiple threads
> dividing tasks into smaller pieces in multiple threads
> using a threadpool
> reporting back out of the threads

read up on these topics:
http://www.eonclash.com/Tutorials/Multithreading/MartinHarvey1.1/ToC.html
or download here :
http://cc.embarcadero.com/item/14809

covering a lot:
http://delphi.about.com/od/kbthread/Threading_in_Delphi.htm
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34143681
oh ... forgot what i find the state of the art piece for multithreading
check the OTL ! (OmniThreadLibrary)

http://www.thedelphigeek.com/
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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