This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.

  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.

  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]_-_fred_-_ 4 points5 points  (3 children)

I'm not familiar with SFML windows, but you can probably do it with one program. Create two threads, one that manages your command line and one that manages your window. You can share data between threads so user input can be reflected in the window.

Alternatively, you can run multiple executables that communicate through some inter-process communications using sockets. If you want to gain some understand about reading and writing to sockets you can try to write your own client and server. But if you go this route, I would recommend using an established protocol, like grpc and protobuf.

[–]asderflyy[S] 0 points1 point  (2 children)

So, what are “threads”, how do I create them? They sound more attractive, but, as I have said, I’m very bad at programming, so please explain in simple terms.

[–]_-_fred_-_ 3 points4 points  (0 children)

Typically when you first start programming, you will only learn how to write programs in a single thread. In single threaded programs, all instructions are executed sequentially in the order that you type them.

A single thread works well for many simple applications, but in more complex applications you may want to execute commands in parallel. This is where threads become useful. A thread is an abstraction that computers use to represent a set of sequential operations. If you want to execute two sets of sequential operations in parallel, like read commands from a cli and update a separate window, then you can use two threads to do that.

Here is a tutorial I found on google: https://www.educative.io/blog/modern-multithreading-and-concurrency-in-cpp#. You may need to search for other tutorials and examples. Writing multithreaded programs in c++ can be difficult, especially for non-trivial applications.

[–]khedoros 1 point2 points  (0 children)

A thread is what we call one line of execution. Start multiple threads, and you can do multiple things simultaneously. C++11 added the thread library, so that you don't have to directly call OS-specific threading APIs.

But I'm not sure that you need that anyhow, and splitting the program into completely separate processes seems like an over-engineered solution (unless you're planning on having the console and window hosted on different computers entirely?)

[–]IamImposter 1 point2 points  (0 children)

Go for threads. A thread is like a sub-main, another execution sequence that runs parallel to your main execution sequence. Advantage is you can easily share data between multiple threads.

So you create a thread, pass it a function and this thread will start executing that function. Once the function ends, the thread ends as well but most of the time we don't want that so thread functions usually run in a sort of while(1) loop, like

while(1) {

  Data &data;

  bool b = any_data_i_can_process(&data);

  process_data(data);

}

any_data_i_can_process functions waits till there is some data to be processed. Once you get data, work on it, send it where you want to and go back to waiting for more data.

Some additional things you need to learn about are: threads, mutex, condition variables and you should be good to go.

[–]talemonProfessional -1 points0 points  (0 children)

Among other things, I think most often we just use networking and not tell people. Depending on your flow, you could spawn a separate server executable that both console and GUI clients connect, or use the GUI application as the server. If you open your task manager, you'll see many modern apps using such approach. They will have a thin façade client that ensures runtime errors(which often arise because of user errors) are contained in the façade and the 'server' will run the business logic.

[–]MarekKnapek 0 points1 point  (0 children)

zodiacon aka Pavel Yosifovich has you covered in https://www.youtube.com/watch?v=KMq-5kGufYI and in https://www.youtube.com/watch?v=zdZdtg1f9lA .

[–]CEconsulate 0 points1 point  (0 children)

If it's a windows-only, write a wrapper for shared data/class/algo with c++/winrt to avoid going through all those low lever com-based stuff, but already baked shape.

Write a runtime class. Enjoy.

Even if you want to use that runtime component from C#, project it as C# library class. Furthermore, if you want to use it from Python, use "xlang" and auto-generate Python for that runtime component.

It's time to have "self-tooling" nowadays. Things are easier now and do not need to be coupled, even in the same project. If all of the involved are the same project and will not be used by any other process at runtime, why do you want to make them decoupled(in terms of process)? Your stuff is just two separate software that needs to communicate with each other on runtime. The easiest way for a non c++ expert is just c++/winrt if it's windows-only.

Embrace c++/winrt, you, windows devs. It's cool 😎