比较快的睡眠排序

    listArr := []int{3, 4, 5, 6, 7, 2, 3}
    a4list := sync.WaitGroup{}
    for _, v := range listArr {
        a4list.Add(1)
        go func(v int) {
            defer a4list.Done()
            time.Sleep(time.Millisecond * cast.ToDuration(v))
            fmt.Println(v)
        }(v)
    }
    a4list.Wait()
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 3

好家伙,我直呼好家伙

2周前 评论

我也贴个php的

<?php

$pIDs =array();
$argc = array(48, 6, 3, 2, 4, 45, 1);
foreach ( $argc as $i) {
    if (($pID = pcntl_fork()) == 0) {
        $sleep = intval($i);
        usleep($sleep*10000);
        echo $sleep . "\n";
        exit();
    } else if ($pID == -1) {
        die();
    } else {

        $pIDs[] = $pID;
    }
}
foreach ($pIDs as $pID) {
    $status = 0;
    pcntl_waitpID($pID, $status);
}

1周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!