What are streams (what is a stream)?

I am always confused with thread concepts. While I do not have the opportunity to use them in a real environment. It would be helpful if someone could explain the topics to me.

+7
multithreading
source share
6 answers

The simple explanation is that you have a job and you get one person to do the job.

This single person is like a stream on a computer.

One person can do one at a time, therefore, to complete a task, he performs tasks of the task, one task at a time, one operation for each task at a time.

To speed things up, you can add more people to the same job. For example, let's say you need to draw a house. You hire 4 people for this.

These 4 people can look like 4 threads, because they work with the same resources (the same house, the same buckets of paint), and they can share the work.

The process would be akin to painting this house.

This simple explanation breaks down a bit when it comes to machines that lack processor cores to run all threads at the same time, but I will ignore it here.

+7
source share

Something no one found explained to me the difference between a process and a thread. Once you understand this when the threads are coming up, that makes a lot of sense.

The operating system uses process memory. A process at startup usually has one "thread" running inside it.

A thread is what the operating system plans to run on the CPU and is given an address to start executing instructions.

Some people who were much smarter than me developed that processes on most operating systems were much more expensive than creating a thread of execution. In addition, two threads in the same process have the ability to access process memory without using an operating system call and / or shared memory, which means that although you now need to synchronize access to thread memory, you could do more work in less time.

Thus, streaming is an important concept for understanding, and its main use was to increase the performance of concurrency programs that could be used, the first main use (EDIT: perhaps this was not the "first") launching the application GUI in one thread and performing processing on another, cornerstone of modern user interface design.

+7
source share

An individual thread is called that because it is one thread of execution through your code. If you have several threads, then you have several threads of execution through your code at the same time (or simultaneously with the support of your single / multi-core system). Both threads have access to the same heap, although they use different stacks. This means that the data in your program can be seen by both streams and can be changed either by a stream. This, of course, can lead to serious problems requiring protection from.

It is worth noting that the flow is different from the process. The key difference is that two threads can access the same data (heaps), while two processes cannot.

For a more detailed description, see other descriptions on the Internet.

wikipedia

+2
source share

At the risk of simplification:

A thread is a line of program execution.

In your basic programming model, the computer simply tracks your program at a time, and only one statement is excluded at any given time. If your program expands or calls another procedure, execution leaves a place where control is transferred and starts to be executed in another place, but still only one is executed at a time.

In threads, several control lines can be executed simultaneously. For example, one part of your program can interact with the user, and the other part downloads a file in the background. Multithreaded programs are much more difficult to program, and much more difficult to envision how they work.

+2
source share

There is a nice page on wikipedia: http://en.wikipedia.org/wiki/Thread_%28computer_science%29

brief summary: flow is an easy process

If you use threads, pay attention to the behavior of each thread and especially to the mutual resources

0
source share

This is the line of execution through the program. and there are two ways to create a stream

0
source share

All Articles