Solved

Single Threading Vs MultiThreading

Posted on 2002-03-31
8
495 Views
Last Modified: 2008-02-01
When should I use single threading over multithreading and vice versa?

I understand the performance issues caused the the need for marhaling while using both single and multithreading but not when I should choose one over the other outside of this.
0
Comment
Question by:Lisp
[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
8 Comments
 
LVL 2

Expert Comment

by:nahumd
ID: 6908599
There is no straight forward way of implementing multithreading in vb (unless you're talking about .net).
Therefore, unless you have a very special need that will make it worth the big effort - you should use single threading.
0
 

Author Comment

by:Lisp
ID: 6908621
OK but can you give me an example of such a big need?  The question was asking when do I need to use each of these.  I am attempting to prepare for an exam and need to know the answer.

Thanks.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6908672
This is not really a VB issue as it applies to any language.   So if you were asking, “why would you want to use multi-threaded tasks?” there are hundreds of examples.  In simple terms: “multithreading should be used to increase throughput.”

Here are the issues to consider:

1) Handling of a multithreaded environment requires additional processing and storage resources.  If a task can complete in less time than the management overhead of the multithreading then throughput would be reduced. In otherworlds don’t use a sledgehammer to crack a nut.
2) Multithreading should be considered to reduce bottlenecks where slow processes are linking to faster processes.
3) There are always exceptions to every rule.
4) The multithreading control should always be aware of its processing limitations (or bandwidth limitations).
5) Multithreading can take better take advantage of resource pools so a slow process can be re-tasked to a different server.

Examples:


1) Bulk Email – Use Multi-threading

A bulk email program can send an email every six seconds.  But when it hits an address where the responding server is slow or just not there, network retires could mean that it could take 30 seconds to decide that and address was bad. By multi-threading the process better throughput can be achieved.  But the cute trick is to monitor the bandwidth so before opening up another thread the thread management should ping an up-line gateway to gauge the response time.  If the response is greater than a preset limit the management should reduce currently operating threads.  So by running perhaps 20 threads you could send perhaps 3 emails per second and the odd slow connection would not stop the ball rolling. The exception - in a LAN environment, where all recipients are local, a multi-threading bulk email may not be so desirable as it may bring the entire LAN to a standstill until the job was complete.

2) Web Server – Use Multi-threading

Reading from a resource is an ideal case for multi-threading.

3) Record Updates – Caution

In a data update situation there is a much more reduced case for multithreading as each thread needs a one-to-one relationship with the resource. Lock the data – update the record – free the lock.

Hope this helps…..

P.S. In VB you can achieve multi-threading in VB6 by using separate exe processes, controlled by a process control exe.  But VB6 is not so good for creating com+ services that run on a server, in this case to would need to use C++ or VB.Net.
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 100

Expert Comment

by:mlmcc
ID: 6908798
listening
0
 

Author Comment

by:Lisp
ID: 6909469
Thanks InTheDark.  The points are yours.  For an extra 100 points will you consider answering this for me?


If I have an application that has multiple add-ins connecting to it should the core application be multi-threaded?

Should the addins also be multithreaded to avoid marshaling or will I achieve a 1 to many relationship between add-ins and the core program by processing the addins in a single threadspace withing the core application if I have single threaded add-ins accompanied by a mulithreaded core program?
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6909924
>If I have an application that has multiple add-ins connecting to it should the core application be multi-threaded?

Again this depends on the task. Suggest you start by following these links, then we can discuss them later:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q243548

http://www.desaware.com/articles/threadingL3.htm
0
 
LVL 17

Accepted Solution

by:
inthedark earned 200 total points
ID: 6912405
>If I have an application that has multiple add-ins connecting to it should the core application be
multi-threaded?

On the face of it would be tempting to say yes. But remember the overhead of threading so the answer is it depends on the tasks.  If the tasks are mainly CPU bound operations then multi-threading will be a waste of time.  If some of the tasks will be resource bound (waiting for a database/another server to bring back data for example), then multi-threading could be an option. Furthermore, if a job is waiting for another operation to complete any marshalling overheads less relevant.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6912553
>Should the addins also be multithreaded to avoid marshaling

If you read the dessaware article I think that it proposes that marshaling takes place when an object is defined on one thread but passed to another thread.  Before the object can be processed the calling thread has to halt the first source thread, pass orver the parameters, execute the function, then copy the results/object back to the calling thread.
0

Featured Post

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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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