?
Solved

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

Posted on 2010-11-15
8
Medium Priority
?
381 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
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 38

Expert Comment

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

and the implementation of the threads ?
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 200 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
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 25

Accepted Solution

by:
epasquier earned 300 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 38

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 38

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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