Solved

Single Threading Vs MultiThreading

Posted on 2002-03-31
8
485 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 119
Visual Studio 2005 text editor 10 38
Added a column screws up code 5 57
VBA - Excel, Hide/unhide range of rows on sheet with listbox selection 9 46
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 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