Which is better: choose vs Threads?

In linux.

I want to create an autoclicker that will have an on / off function when a key is pressed. Obviously, there should be 2 things in parallel (the clicker itself and the on / off function)

What are the disadvantages and advantages of each implementation: Using a thread that will handle the auto-wedge function and another main thread (for turning on / off, etc.) Or by choosing syscall and waiting for input / keyboard?

+7
source share
2 answers

Using select better for performance, especially if you can have hundreds of simultaneous operations. However, it can be difficult to write code correctly, and the coding style is very different from traditional single-threaded programming. For example, you need to avoid calling any blocking methods, as this may block your entire application.

Most people find using streams easier because most of the code is like regular single-threaded code. The only tricky part is those few places where you need cross-talk through mutexes or other synchronization mechanisms.

In your particular case, it seems that you only need a small number of threads, so I would go for a simpler programming model using threads.

+7
source

Given the amount of work you do, this probably doesn't matter.

For high-performance applications, there is a difference. In these cases, you need to process several thousand connections at the same time; in such cases, you transfer new connections to new streams.

Creating several thousand threads is expensive, so the choice is used to increase efficiency. In fact, different methods are used for optimal switching, such as kqueue or epoll .

I say that this does not matter, because you are probably only going to create a thread once and have exactly two threads working for the lifetime of the application.

+1
source

All Articles