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

CSharp_张师浩_无22 #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sh-zhang22
Copy link

No description provided.

@@ -11,8 +11,8 @@ public static void Main(string[] args)
new Thread
(
() =>
{
Console.WriteLine("A Start: "+(a.Start(2000)).ToString());
{//此处进行了一定修改,否则从原理上好像达不到示例输出效果
Copy link
Owner

Choose a reason for hiding this comment

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

显然是代码存在bug啊

private static long startTime = 0;

private static long bar = 0;//Environment.TickCount64;
private static long req = 0;
Copy link
Owner

Choose a reason for hiding this comment

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

怎么能用static呢?

if(bar > req)
bar = req;
return (bar, req);
}
Copy link
Owner

Choose a reason for hiding this comment

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

没有采用任何锁或者原子操作保证线程安全


private static long startTime = 0;

private static long bar = 0;//Environment.TickCount64;
Copy link
Owner

Choose a reason for hiding this comment

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

bar完全可以作为局部变量,不需要作为字段

/// </summary>
public void Set0()
{
bar = 0;
Copy link
Owner

Choose a reason for hiding this comment

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

这没有任何意义啊

bar = Environment.TickCount64 - startTime;
if (bar < req)
{
bar = 0;
Copy link
Owner

@shangfengh shangfengh Sep 20, 2023

Choose a reason for hiding this comment

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

没有任何意义的操作,没有实现TrySet0的功能
请想明白如何实现进度清零的目标

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

Successfully merging this pull request may close these issues.

2 participants