| |

VerySource

 Forgot password?
 Register
Search
View: 778|Reply: 3

Question about a thread

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-17 21:30:01
| Show all posts |Read mode
There is an endless loop in thread A. The exit of the endless loop depends on thread B running to somewhere A. Currently, the busy waiting method is used, that is, the loop exit flag flag is modified at point A in thread B. Endless loop measurement
Try the mark and exit. But when I'm so busy waiting for too much time, I want to change the method.

I want to use the condition variable method, but waiting for the arrival of the signal in the loop of thread A will hang up A, because A must run constantly, so it cannot be suspended.

Is there any way for everyone?
Thank you!
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-6-22 10:00:01
| Show all posts
I don’t understand, since A wants to "run non-stop" and can't stop, why can't it be detected in time during operation?
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 18:15:01
| Show all posts
You can add pthread_cond_wait

When B runs for a certain period of time, issue pthread_cond_signal to activate A.


For reference, I don’t know if it works for you
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 18:45:01
| Show all posts
However, waiting for the arrival of the signal in the loop of thread A will suspend A. Since A must run continuously, it cannot be hung up. ???

why?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list