당신이 GLib.Thread에 대해 말하고 있다고 가정하면, 그렇게 할 수 없습니다. 비록 당신이 할 수 있더라도, 당신은 아마도 당신이 상당한 양의 메모리를 새기게 될 가능성이 있기 때문에, 그러고 싶지 않을 것입니다.
당신이해야 할 일은 스레드가 스스로를 죽일 것을 요구하는 것입니다. 일반적으로 이것은 가장 빠른 기회에 작업이 중지되도록 요청되었는지 여부를 나타내는 변수를 사용하여 수행됩니다. GLib.Cancellable은이를 위해 설계되었으며 GIO의 I/O 연산과 통합됩니다.
예 :
private static int main (string[] args) {
GLib.Cancellable cancellable = new GLib.Cancellable();
new GLib.Thread<int> (null,() => {
try {
for (int i = 0 ; i < 16 ; i++) {
cancellable.set_error_if_cancelled();
GLib.debug ("%d", i);
GLib.Thread.usleep ((ulong) GLib.TimeSpan.MILLISECOND * 100);
}
return 0;
} catch (GLib.Error e) {
GLib.warning (e.message);
return -1;
}
});
GLib.Thread.usleep ((ulong) GLib.TimeSpan.SECOND);
cancellable.cancel();
/* Make sure the thread has some time to cancel. In an application
* with a UI you probably wouldn't need to do this artificially,
* since the entire application probably wouldn't exit immediately
* after cancelling the thread (otherwise why bother cancelling the
* thread? Just exit the program) */
GLib.Thread.usleep ((ulong) GLib.TimeSpan.MILLISECOND * 150);
return 0;
}
왜 당신이 스레드를 죽이고 싶어합니까? 너 정말로 무엇을하려고하는거야? – razeh
내가 원하는 것을 설명하기 위해 문제 문을 편집했습니다. – imagin
Appart가 새기고 있음을 알 수없는 상태로 많은 데이터를 남겨두고 있습니다. 그것은 거의 좋은 생각이 아닙니다. 중지 할 스레드에 신호를 보내고 중지 요청을 확인하십시오. –