[Solved] C/C++ code using pthreads to execute sync and async communications

[ad_1] There is no general problem with two threads executing system calls on the same socket. You may encounter some specific issues, though: If you call recvfrom() in both threads (one waiting for the PLC to send a request, and the other waiting for the PLC to respond to a command from the server), you … Read more

[Solved] Convert a process based program into a thread based version?

[ad_1] The general case depends on whether the threads are wholly independent of each other. If you go multi-threaded, you must ensure that any shared resource is accessed appropriate protection. The code shown has a shared resource in the use of srand() and rand(). You will get different results in a multi-threaded process compared with … Read more

[Solved] where is the pthread segfault happening?

[ad_1] You use of strtok() is wrong: line = strtok(buffer, NULL); should be line = strtok(NULL, delim); Another mistakes should be fixed similarly. The elements of text_lines are uninitialized: text_lines = malloc(6000 * sizeof(char*)); this allocated 6000 pointers to char, but none of these pointers are initialized. 0 [ad_2] solved where is the pthread segfault … Read more

[Solved] Error while compiling the code ‘double free or corruption (out)’ using threads in C? [closed]

[ad_1] The *fp is a global variable, so each therad will initialize it with fopen and after finished working try to close it. the *fp is shared between threads (which should not be) so each thread before exiting tries to close the file handle stored in *fp and the double free occurs when multiple threads … Read more