首页 > 其他分享 >讨论jiffies回转的time_after比较函数

讨论jiffies回转的time_after比较函数

时间:2024-10-08 15:11:04浏览次数:1  
标签:printf lb la after llu jiffies time lld

本文讨论jiffies回转的比较函数:

#define time_after(a, b) \
        ((long)(b) - (long)(a) < 0)

写了个例子如下:
#include <stdio.h>
#include <stdint.h>


#define time_after(a, b) \
        ((long)(b) - (long)(a) < 0)

int main() {

        unsigned long la = 0x8000000000000000;
        unsigned long lb;

        lb = la - 1;
//      la--;
//      lb--;

        printf("la: %llu, %lld, %d\n", la, la, sizeof(la));
        printf("lb: %llu, %lld, %d\n", lb, lb, sizeof(lb));

        if (time_after(la, lb)) {
                printf("la(%llu) after lb(%llu);\n", la, lb);
                printf("la(%lld) after lb(%lld);\n", la, lb);
        } else {
                printf("la(%llu) not after lb(%llu);\n", la, lb);
                printf("la(%lld) not after lb(%lld);\n", la, lb);
        }

        return 0;
}

 

运行结果如下:

 9223372036854775808 就是0x800000000000, 把它加一就变成负数了。

参考一下,int8的正负号序列:

 

 

于是这里有个问题:

9223372036854775807 - -9223372036854775808 = 18446744073709551615 

为什么可以成立。

因为18446744073709551615 转化成有符号数 -1了。

 

另外回转有效的前题是,回转值小于1/2的max(uint64)。

 

标签:printf,lb,la,after,llu,jiffies,time,lld
From: https://www.cnblogs.com/hugetong/p/18451691

相关文章

  • Linux基础命令uptime详解
    uptime 命令在Linux中用于显示系统的运行时间、当前登录用户数以及系统负载信息。这个命令非常简单,但是它提供的信息对系统管理员和用户来说非常有用。基本语法uptime[OPTION...]输出说明当你运行 uptime 命令时,输出通常包含以下几个部分:当前时间:系统当前的时间。......
  • ICMP timestamp请求响应漏洞CVE-1999-0524解决方法
    ICMPtimestamp请求响应漏洞CVE-1999-0524解决方法1、添加进和出的规则firewall-cmd--permanent--direct--add-ruleipv4filterINPUT0-pICMP--icmp-typetimestamp-request-mcomment--comment"denyICMPtimestamp"-jDROPfirewall-cmd--permanent--direct--ad......
  • XTimer定时微服务项目
    Xtimer定时微服务项目背景在学校社团中,有给社团成员发送活动通知的任务需求有定期执行某项任务的需求,比如每周末举办一次线下活动,每个月举行一次团建再比如,我有一个任务需要设置定时发布定时微服务调研对比方案不足点JavaTimer单线程,任务堆积RocketMq可以作为......
  • ​解密 Go runtime.SetFinalizer 的使用
    解密Goruntime.SetFinalizer的使用原创 GoOfficialBlog GoOfficialBlog  2024年10月05日18:45 中国香港 听全文如果我们想在对象GC之前释放一些资源,可以使用returns.SetFinalizer。这就像在函数返回前执行 defer 来释放资源一样。例如:1:使用runtime.......
  • kube-ovn net/http TLS handshake timeout
    问题现象业务报错net/http:TLShandshaketimeout。容器IP跨节点访问kube-apiserverserviceclusterIP不通。问题分析kkotrace[ns]/[pod][ip]tcp443|grep对端主机ipkube-ovn在br-int网桥上刷流表实现了kube-proxy的dnat功能。kube-ovn监听service的endpoints,像kub......
  • WPF ListBoxItem Selected and background changed at the same time via ItemContain
    <Window.Resources><Stylex:Key="lbxItemContainerStyle"TargetType="ListBoxItem"><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType=&quo......
  • WPF ListBox ListBoxItemTemplate display image automatically via System.Timers.Ti
    //xaml<Windowx:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.micr......
  • 题解:SP7973 ACPC10E - Sometimes, a penalty is good!
    比较简单的一道数学题。思路:计算小组赛的比赛总数。longlongstage1=G*T*(T-1)/2;每组有\(T\)个队伍,每个队伍都需要与其他\(T-1\)个队伍比赛,共有\(T\cdot(T-1)\)场比赛。共有\(G\)组,因此小组赛总比赛数为\(\frac{G\cdotT\cdot(T-1)}{2}\)。计算进入......
  • transaction_timeout:达到事务超时时终止会话
    功能实现背景说明我们已经有两个参数来控制长事务:statement_timeout和idle_in_transaction_session_timeout。但是,如果事务执行的命令足够短且不超过statement_timeout,并且命令之间的暂停时间适合idle_in_transaction_session_timeout,则事务可以无限期持续。在这种情况下,tra......
  • PbootCMS缓存runtime能删除吗?空间满了怎么办?
    PbootCMS缓存文件夹 runtime 的处理方法1. runtime 文件夹可以删除吗?可以删除:runtime 文件夹中的缓存文件是可以随意删除的,不会影响网站的功能。建议定期清理:定期清理缓存文件有助于释放空间,提高系统性能。2.删除方法后台清理:登录PbootCMS后台。点击右上角的......