1

I've got a service that can get self uninstall command. In this case It should call the uninstall command from the generic commandHandler that may handle many other commands.

After receiving the uninstall command, I'd like to halt the current thread from handling any additional commands.

void ExecuteUninstall() {
  uninstallBackground();
  do { sleep(100); } while(1); // wait idle.
}

I was wondering if there's any better approach for waiting for the process to terminate itself ? Until the process is removed externally, the process should continue running except for this thread ... so an alternative solution could be to kill this thread from within. and leave the other threads functioning.

Thanks !

Zohar81
  • 4,554
  • 5
  • 29
  • 82
  • Just set a flag that the thread you want to shut down inspects regularly and terminates itself gracefully when it sees that it has been set. Does that work for you? – Paul Sanders Nov 23 '21 at 14:38
  • How do you terminate the current thread gracefully ? do you have cross platform way to do it ? – Zohar81 Nov 23 '21 at 14:40
  • If you are using pthreads, you can call `pthread_exit` from anywhere within the thread. Otherwise you have to return from (or reach the end of) the initial function that was called when the thread started running. Or you can throw an exception, catch it in that function and then return from there. – Paul Sanders Nov 23 '21 at 18:22

0 Answers0