Tuesday, September 03, 2019

starting offline processing in a new thread - C++

Tried various options to begin processing in a new thread for BscanFFT, without locking the UI - 

Just
std::system(offlinetoolpath);
// - this causes the BscanFFT program to wait for the offline tool to finish

Then,

pid = fork();

if (pid == 0)

{

// child process

std::system(offlinetoolpath);

}

else if (pid > 0)

{

// parent process

}

gives the error

 [xcb] Unknown sequence number while processing queue

[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called

[xcb] Aborting, sorry about that.

BscanFFTspinj.bin: ../../src/xcb_io.c:259: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

Apparently, system specific is safer, http://www.cplusplus.com/forum/beginner/13886/

"Actually, the most important disadvantage of system() is that it introduces security vulnerabilities. Using a system-dependent method (that skips the shell) is always safer.

In Windows, it is CreateProcess(), which is really straight-forward to use.

In POSIX (Linux, etc) it is a combination of fork() and one of the exec() functions.

http://linux.die.net/man/2/fork

http://linux.die.net/man/2/execve

http://linux.die.net/man/3/execv

These are also easy to use, but there are some caveats. Follow the example codes."

execve with the example code gave
(show:9323): Gtk-WARNING **: 10:47:16.601: cannot open display:

https://stackoverflow.com/questions/2437819/gtk-warning-cannot-open-display-when-using-execve-to-launch-a-gtk-progra/2437850#2437850

suggested using execv instead. This worked.


No comments:

Post a Comment