Solved

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

Posted on 2010-11-15
8
379 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 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
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!

 
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

Technology Partners: 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!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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