I've read various articles and similar questions, and I know that the two concepts are different, but I don't seem to know the correct answer.
I understood that thread
is in terms of number of workers, and sync/async
is in terms of task order.
I would like to ask if my understanding is correct, with the following example.
Have to make a sandwich.
- Bake bread.
- Fry the eggs.
- Combine.
A thread == a frying pan.
- Single-thread & sync:
- Put the bread on the frying pan.
- just watch until the bread is all baked.
- When the bread is baked, remove the bread from the pan and put the eggs on that pan.
- Multi-thread & async:
- Multiple pans.
- Put the bread and eggs on different pans, respectively.
- No matter what you put first, take out the completed one.
- Single-thread & async:
- One pan.
- Put the bread on the pan.
- The bread was not all baked, but put it aside for a while and put the eggs on that pan.
- The eggs aren't all fried, but I'll just put them away and put the bread on the pan.
- Repeat...
- Multi-thread & sync:
- There are several pans, but we will bake the bread on pan1 first.
- When the bread on pan1 is finished, fry the eggs on pan2.
Is my understanding correct?
+) If so, case single-thread / async like javascript, the task in the event loop is just waiting in the queue and not progressing, right?