Solved

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

Posted on 2010-11-15
8
369 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 36

Expert Comment

by:Geert Gruwez
Comment Utility
owch , my eyes !
where is the indenting ?

and the implementation of the threads ?
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 50 total points
Comment Utility
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
Comment Utility
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
 
LVL 25

Accepted Solution

by:
epasquier earned 75 total points
Comment Utility
> 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 25

Expert Comment

by:epasquier
Comment Utility
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
Comment Utility
Thanks
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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 36

Expert Comment

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

http://www.thedelphigeek.com/
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now