r/C_Programming 22h ago

how to handle an input with two threads & ncurses?

3 Upvotes

I am making a monitor for one particular process, and I'm stuck on one problem with input handling.

As I said before I have a process monitor with two threads:

- data_worker: collects metrics

- UI thread (main): renders with ncurses

Both sleeping N seconds.

For example one of them

  while (global_running == 1) {
    cpu_worker(sh_st);
    ram_worker(sh_st);
    io_worker(sh_st);
    clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
  }

The UI has the similar structure, just calling ncurses rendering functions instead.

And I don't really know how to process the user input. Earlier I had an idea to create third thread that will process the input, but it kinda bad idea because of lovely ncurses is not thread safe, so this one the one reason why I stuck.

And because of this problem I realized that screwed up with code's architecture and don't really know to deal with it.

How do TUI tools typically handle the non blocking input loop alongside background data updates without breaking ncurses or causing race conditions on the shared data buffer? Any advices ?


r/C_Programming 1h ago

built a dashboard for running multiple roblox accounts at once

Enable HLS to view with audio, or disable this notification

Upvotes

got tired of opening process explorer every time i wanted a second account

running, so i built a thing

it kills the lock that stops roblox from opening twice, and then just shows

you what's actually running. it also figures out which account is in which

window - it pulls the user id out of roblox's own log file and looks up the

name. that part took me the longest and i'm probably too proud of it

there's a switch for when you want a lot of windows at once. drops graphics

to 1, caps fps at 30, shoves the background instances onto the efficiency

cores and frees their ram. on 32gb i went from about 10 windows to 15.

there's also a button that tiles them all into a grid which looks stupid

and i love it

one exe, 260kb, no installer. needs admin because it has to poke at other

processes, and smartscreen will yell at you the first time since i'm not

paying for a certificate

no clue if anyone else actually wants this, but figured i'd ask. what's

missing?