Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduction to Threading submission #57

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

dakshdeepHERE
Copy link

@dakshdeepHERE dakshdeepHERE commented Jun 13, 2023

Description

This article have detailed information about what exactly threads are. What are the difference between threads and process. How to implement threads using C and Pthread lib.

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • Under "Development" on the right, I have linked any issues that are relevant to this PR (write "Closes # in the "Description" above).

Fixes #31

@CLAassistant
Copy link

CLAassistant commented Jun 13, 2023

CLA assistant check
All committers have signed the CLA.

@dakshdeepHERE
Copy link
Author

I have one suggestion: Please review the first code example provided in the PR file. I have attached a screenshot of my CLI showing the output, and I have also written the output in the shell. You can choose whichever approach you prefer, and we can proceed with that, deleting the alternative entry.

Copy link
Contributor

@CBID2 CBID2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dakshdeepHERE! :) I gave some feedback on your article. Looks pretty good so far! :) (Note: I'm not a maintainer. Just a friendly contributor who wanted to help you. 😄).

@dakshdeepHERE
Copy link
Author

Hey @CBID2 I never knew we were allowed to review others code and suggest changes. This is a good practice imo to help maintainers. Maybe I would do some code reviews too if they are from my tech stack from next time.

@CBID2
Copy link
Contributor

CBID2 commented Jun 14, 2023

Oh of course we can @dakshdeepHERE! It's a common practice in open source! :) I wrote a FreecodeCamp article on how to review people's code. Check it out! 😊

@dakshdeepHERE
Copy link
Author

@CBID2 yes I do that in other repo owned by my friend but I thought it's against the TOS here.

@CBID2
Copy link
Contributor

CBID2 commented Jun 14, 2023

@CBID2 yes I do that in other repo owned by my friend but I thought it's against the TOS here.

I don't think it is @dakshdeepHERE.

@yangc95 yangc95 self-assigned this Jun 14, 2023
@yangc95 yangc95 added the status: under review Issue or PR is currently being reviewed label Jun 14, 2023
@dakshdeepHERE
Copy link
Author

Hey @yangc95 I have few more optional codes that I wanted to add but I didn't as the article already is above 300 lines. If you want I can add them. But I think the code samples of creating threads for the functions and message between threads are enough for basic understanding of threads.

Copy link
Collaborator

@yangc95 yangc95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dakshdeepHERE Thanks for your patience!

I conducted a review and left comments. Please let me know if you need anything clarified! In addition. The comments are a bit open-ended due to the nature of a tutorial article which you'll notice.

Let me know once you've addressed any requested changes 🙂

- "learn-python"
- "paths/threading"
---

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we place links here, it should look like:

...more links
(space here between links and images)
[image1]: image link

Then in the content, you'd just mention the link like [this]

content/dakshdeephere/threading.md Outdated Show resolved Hide resolved
content/dakshdeephere/threading.md Outdated Show resolved Hide resolved
Comment on lines +23 to +24
A `thread` is a path of execution within a process, which can contain multiple threads. It is also known as a lightweight process. The goal of threading is to achieve parallelism by dividing a process
into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses multiple threads: one to format the text and another to process inputs, etc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `thread` is a path of execution within a process, which can contain multiple threads. It is also known as a lightweight process. The goal of threading is to achieve parallelism by dividing a process
into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses multiple threads: one to format the text and another to process inputs, etc.
A `thread` is a path of execution within a process, which can contain multiple threads. It is also known as a lightweight process. The goal of threading is to achieve parallelism by dividing a process into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses multiple threads; one thread may format the text while another another processes inputs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant definition! Could we also include a short definition on processes here? Also, what about concurrency v parallelism

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure to place focus on what this tutorial will accomplish in the intro


## Process vs Thread

| S.N. | Process | Thread |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we swap out S.N for something more meaningful or remove it


**`Thread`** is an execution unit that consists of its own program `counter`, a `stack`, and a set of `registers`. `Program counter` keeps track of which instruction to execute next, the system registers which hold its current working variables, and a stack that contains the execution history.

**A thread comprises of:**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would work well as a numbered list

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd also be good to have a short explanation on what each is

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would work well as a numbered list

Haha I'm so used to this listing that I've literally stopped using the numbered list

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd also be good to have a short explanation on what each is

Got it


## Multithreading

- A `thread` is a path which is followed during a program’s execution.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be good for Docs formatting. As this is an article, can we use paragraph format unless we're creating some itemized list or specifically listing out parts of some kind

- `Data dependency` – sometimes the data required by one thread (T1) might be produced by another (T2). Thus, T1 can not run before T2. Therefore, it becomes difficult for programmers to code.
- `Testing and debugging` – Multiple threads running in parallel on multiple cores poses another challenge in the testing of applications.

## Syntax
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Syntax
## Creating a thread

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's turn the content below into a step-by-step tutorial and slowly add in code w/ explanations


Remember to link your program with the `pthread` library by adding `-pthread` to the compiler command during the compilation process.

## Examples
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use meaningful headings which explain the step the learner is going to go into next

content/dakshdeephere/threading.md Outdated Show resolved Hide resolved
@dakshdeepHERE
Copy link
Author

@yangc95 Thank you for the amazing review I will get started with the changes. I'm totally blown away by the range of your knowledge in computer science after reading your comments in this entry. Devs like you always motivate me. Thanks for the correction.

@yangc95
Copy link
Collaborator

yangc95 commented Aug 31, 2023

@dakshdeepHERE Hiya! Just pinging you on this as a light reminder 🙂 hope your studies are going along!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Topic Idea] Introduction To Threading
4 participants