lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 27 Jun 2022 22:45:29 +0000
From:   Wedson Almeida Filho <wedsonaf@...gle.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Tejun Heo <tj@...nel.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        "Eric W. Biederman" <ebiederm@...ssion.com>,
        Christian Brauner <brauner@...nel.org>,
        Petr Mladek <pmladek@...e.com>,
        Lai Jiangshan <jiangshanlai@...il.com>,
        Michal Hocko <mhocko@...e.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Oleg Nesterov <oleg@...hat.com>
Subject: Re: [PATCH 3/3] kthread: Stop abusing TASK_UNINTERRUPTIBLE
 (INCOMPLETE)

On Tue, Jun 28, 2022 at 12:06:29AM +0200, Peter Zijlstra wrote:
> On Mon, Jun 27, 2022 at 06:04:12PM +0000, Wedson Almeida Filho wrote:
> 
> >   let new_thread = task::new_paused(|| pr_info!("Hello world\n"))?;
> 
> I'm still having a really hard time with this Rust stuff, the above
> looks like a syntax error and random characters to me :/

Fair enough, there are a few things going on there. The code above could
be expanded to the following:

  fn thread_func() {
    pr_info!("Hello world\n");
  }

  let retval = task::new_paused(thread_func);
  if retval.is_err() {
      return retval.unwrap_err();
  }

  let new_thread = retval.unwrap();

I hope the above is clearer. The question-mark operator is just
syntax-sugar for the error handling above, the pipes indicate a closure,
the full syntax is: |args| -> ret_type { statement1; statement2; etc. }
-- the line you quote has the compiler infer the type (so it's omitted),
there are no args (so the nothing between the pipes), and when there's a
single statement that is an expression whose type matches the return
type, the curly braces can thus be omitted, so we end up with "|| x" as
the closure.

I'm confident people can get used to this. It's in the rare cases when
one has to think about say subtyping, invariance, covariance, and
contravriance that things may get hairy (or exciting for the more
math-inclined).

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ