views:

107

answers:

5

I am looking to learn more about threading and I wanted to know: what is a multithreaded application?

+1  A: 

It's an application that uses more than one thread internally to accomplish its goal.

There are lots of examples, as most application that need to interact with a user have a UI thread and a set of working threads. This is done to allow the UI to remain responsive while the application is busy doing some task.

Welbog
Process != thread
ripper234
A: 

A multi-threaded application takes advantage of running multiple tasks at the same time to speed things up. Multithreading can also take advantage of multiple CPU machines.

Mark Redman
A: 

It's an application that can do multiple things at once. For example, if you're tying a document in Word, there's a thread responding to your keyboard, there's a thread that's checking your spelling, there's one that's checking your grammar, there may be another thread saving a backup of your document in case the program crashes.

eduffy
A: 

It is a program that uses more than one thread. The different threads can access shared memory structures (usually by using appropriate synchronization mechanisms, e.g. locks). An example would be a program that downloads a few files concurrently, each download using a different thread to speed up the download process (there are more sophisticated ways to achieve that, this is just an example).

Multi-threading is often used on CPU-bound tasks, that benefit from using all cores in a modern computer (e.g. trying to break a cypher using multiple processors).

The difference between a thread and a process is that different processes usually cannot directly share memory and data structures, although various mechanisms to share information between processes exist (they are usually more costly than sharing information between threads).

ripper234
+5  A: 

Multithreading as a widespread programming and execution model allows multiple threads to exist within the context of a single process. These threads share the process' resources but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. However, perhaps the most interesting application of the technology is when it is applied to a single process to enable parallel execution on a multiprocessor system.

That means that a single process can have many different "functions" executing concurrently, allowing the application to better use the available hardware (multiple cores/processors). Threads can communicate between them (they have shared memory), but its a hard problem to have every thread behave well with others when accesing shared objects/memory.

Threading allows an application to remain responsive, without the use of a catch all application loop, when doing lengthy operations.

For example, a non threaded copy program wouldn't allow you to do anything until the copy completes.

Threading helps with complex, lenghty, independent problems, but brings along a lot more complexity, that makes it hard even for seasoned developers.

voyager