[PATCH] D39710: Simplify unlinkAsync

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 12:11:29 PST 2017


I don't know if it's relevant, but even on Windows, the behavior described here (that the process exits if the main thread exits even while other threads are running) only occurs if the main thread exits via the CRT. Exiting the main thread by calling ExitThread directly will leave the process running. See https://blogs.msdn.microsoft.com/oldnewthing/20100827-00/?p=13023.

From: llvm-commits <llvm-commits-bounces at lists.llvm.org> on behalf of Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org>
Reply-To: Rui Ueyama <ruiu at google.com>
Date: Tuesday, November 7, 2017 at 11:17 AM
To: Rafael Avila de Espindola <rafael.espindola at gmail.com>
Cc: "arichardson.kde at gmail.com" <arichardson.kde at gmail.com>, "reviews+D39710+public+26765ebae200d03e at reviews.llvm.org" <reviews+D39710+public+26765ebae200d03e at reviews.llvm.org>, llvm-commits <llvm-commits at lists.llvm.org>
Subject: Re: [PATCH] D39710: Simplify unlinkAsync

On Tue, Nov 7, 2017 at 11:08 AM, Rafael Avila de Espindola <rafael.espindola at gmail.com<mailto:rafael.espindola at gmail.com>> wrote:
Rui Ueyama via Phabricator <reviews at reviews.llvm.org<mailto:reviews at reviews.llvm.org>> writes:

> ruiu added inline comments.
>
>
> ================
> Comment at: ELF/Filesystem.cpp:19
>  #include "llvm/Support/FileSystem.h"
> +#include <unistd.h>
>
> ----------------
> Does all system have unistd.h?

Looks like I have to check defined(HAVE_UNISTD_H). I will add that.

>
>
> ================
> Comment at: ELF/Filesystem.cpp:54
>
> -  // Remove TempPath in background.
> -  runBackground([=] { ::remove(TempPath.str().str().c_str()); });
> +  sys::fs::remove(Path);
> +
> ----------------
> Is this safe on Windows? On Windows, you can't remove opened files.

It depends on how they are opened. We use FILE_SHARE_DELETE in
openFileForRead, so it should work.

But in fact, remove being slow is a unix only problem, so I guess the
best thing to do is to return early on windows. I will add that too.

Makes sense.

I believe that it is only a Windows thing that the entire process dies with some error condition when the main thread exits while other threads are running. So, we might be able to remove runInBackground and just detach a thread that we create for calling close(2).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171107/20e1fc83/attachment.html>


More information about the llvm-commits mailing list