Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-11-15
8
Medium Priority
?
385 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
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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

597 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