r/AskComputerScience • • 1h ago

Checking my understanding about threads and parsing

Hello, after countless discussion and confusion with chatGPT and seeing multiple resources about threads (or more specifically software threads), and parsing, i finally came up with a conclusion, and just wanted to see if what i'm saying "makes sense" or if i'm missing the point.

Threads are independent flow of execution, they contain necessary information for the cpu to start or resume executing a piece of code, so they represent a flow of execution of a piece of code (they can represent many flow of executions but only one at a time) and, they also represent the current state of execution of that piece of code.

Threads are used in two scenarios (afaik):

  • To not block the concerned flow of execution : basically if a specific piece of code contains a blocking or multiple blocking tasks (or in other words instructions that times alot of time to execute), when the cpu executes these tasks/or instructions that are blocking, the entire flow of execution will be blocked, following instruction will have to wait for the current one to be finished executed by the cpu, this is a problem if the entire piece of code represents something like UI logic, where instructions have to be executed as soon and as fast as possible, for the program interface to be responsive, if the flow of execution of that piece of code that is linked to a specific thread (main thread most of the time) and, represents the UI logic, is blocked, the entire program interface will be too, so it becomes unresponsive. One of the solutions is to separate that specific flow of execution of that specific blocking part of the piece of code into a separate flow of execution represented by another thread. (another solution is using asynchorny mechanism like coroutines or generators without creating threads)
  • To improve the performance: since threads most of the time will be executed concurrently (and possibly in parallel depending on the circumstances), we can separate general tasks into smaller tasks, each task can be given to a thread to improve perforamce (well it depends, since creating more threads can be the opposite, since context switching is costly and adding more threads just adds more time for a specific thread to reach its turn to be executed)

For parsing, it's a process of analysing a group of bits according to a specific format, then extracting these necessary part of the bits and storing them into their corresponding/linked variables or data structures (sometimes these group of bits are represented in another form before they are stored???? not sure)

You may wonder why i keep over repeating stuff, i have OCD especially in "defining words" as correct as possible and to be as less confusing as possible (and also i need to spit out words in a somewhat normal pace, without pauses or else it feels like i'm just remembering the words and that's it, without understanding them), i'm a bit worried the receiver won't understand a thing and i'll be embarassed (it's like i'm just saying nonsense and it feel like i don't know a thing), and most explanations of computer science terms in general are overloaded and complicated for some unexplainable reason, and also nobody seems to be in agreement of what a term exactly means, it just doesn't help at all. (for example threads are defined as execution context or unit of execution, while this may seems understandable to some, i can assure you beginners won't get a thing from this). Anyways just wanted to metion this, i know this isn't the right subreddit to "vent" but i'll just risk it.

Anyways, just wanted to see if my explanations are delusional and incorrect or not.

Thanks for reading.

0 Upvotes

1 comment sorted by

2

u/ghjm MSCS, CS Pro (20+) 1h ago

Your explanation of threads is generally correct, but I'm not sure why you're mixing in concepts from parsing. The two are not strongly related.