Contextual flow switching

I am working on a C / C ++ project, which includes an interface and a background service that does some heavy processing, getting data over the network. So that my user interface does not stop responding, I would like to create a separate thread and then call the background service in that thread, while the other thread will display an indication of busy in the user interface. As soon as the background service completes this task, I want to switch the thread context from the background thread to the user interface thread so that the busy indication is removed and additional screen streams can be shown. I think this is the usual way most user interfaces work. What I would like to know are effective and best ways to achieve this. Right now I have no code implemented for the above,and I just ask for ideas and best ways to do this.

The platform is Linux. The UI framework that I use is a custom UI framework that provides an SDK for developing a user interface, but unlike most UI frameworks, it does not provide anything for the scenario mentioned. This is an almost obsolete structure, but it needs to be used for this project, and it’s a pain, so I can use Pthread or System v with some wrappers over actual calls that will help me keep the implementation portable across platforms.

I cannot use Boost Threads due to certain limitations of the embedded environment.
Any suggestions and explanations on how the context switch happens will be really helpful.

+3
source share
3 answers

First of all, you are confused about how threads work. You cannot switch thread contexts on your own; the operating system does this whenever you want.

Secondly, if your problem is with context redistribution, you are doing something very wrong.

, . "" , , . , , , - "" . - ; .

+6

pthreads. / / . , , ( ), pthread. - .

0

.

  posix ( , ). , ; , , .

, .

0

Source: https://habr.com/ru/post/1773835/


All Articles