How to run a thread after another?

后端 未结 3 480
一整个雨季
一整个雨季 2021-01-28 00:22

Create three threads and the main thread. Execute each thread as simultaneous tasks. Display information when exiting each thread.

3条回答
  •  Happy的楠姐
    2021-01-28 01:06

    It's unclear what you want three threads to do. With two threads you have one waiting on the bool to be false and one waiting on it to be true, right? With three threads you need three states to wait on. You also need to be really careful to set it up in a way so the state transitions happens exactly in the right order and a set amount of times.

    Either try to write that program, and tell us what goes wrong, or if you want design help it might be good to tell us more about what you want to achieve in the end.

    A suggestion if you have a real multithreaded problem that needs to be solved is to look into something like queues. They are really nice high level abstractions that makes working with threads much nicer.

    More likely though, you have some artificial task that needs to be solved, and then you need to speak a bit about the constraints you have.

提交回复
热议问题