Solved

Single Threading Vs MultiThreading

Posted on 2002-03-31
8
500 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

739 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