Search found 69 matches

by Ksawery
Sat Oct 19, 2019 2:40 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Re: Delete thread with blocking function

I managed to find (what I hope is) a good solution to the problem, by following these recommendations: https://github.com/stephane/libmodbus/issues/452 I made the TCP/IP socket non-blocking, using the following function: fcntl(socket, F_SETFL, fcntl(socket, F_GETFL, 0) | O_NONBLOCK); This effectivel...
by Ksawery
Fri Oct 18, 2019 5:34 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Re: Delete thread with blocking function

cough...cough... it's definitely not linux What do you mean, this is under Linux Mint, Eclipse IDE :D if your lib has internal threads and has not explicit functions kinda stop_lib, terminate... you must not try to stop something inside it. I don't think the library provides any way to interact wit...
by Ksawery
Fri Oct 18, 2019 1:57 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Re: Delete thread with blocking function

Here are the threads running in the application: Temporary breakpoint 1, main (argc=1, argv=0x7fffffffddc8) at ../cPomiarWiazki.cpp:3 3 wxIMPLEMENT_APP(cPomiarWiazki); [New Thread 0x7fffeb904700 (LWP 3993)] [New Thread 0x7fffeb103700 (LWP 3994)] [New Thread 0x7fffea3f1700 (LWP 3996)] [New Thread 0x7...
by Ksawery
Fri Oct 18, 2019 1:41 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Re: Delete thread with blocking function

I still get the following message, despite using Kill(): 15:41:27: Debug: 1 threads were not terminated by the application. So I guess I can't do anything until the blocking function returns? Im undertand though, that the thread is terminated, and the heap resources are freed anyway, when the app cl...
by Ksawery
Fri Oct 18, 2019 1:13 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Re: Delete thread with blocking function

I use the following code to terminate the thread: //Delete TCP/IP thread { wxCriticalSectionLocker enter(mbThreadCS); if (mbThreadTCP) { if (mbThreadTCP->Kill() != wxTHREAD_NO_ERROR) wxLogError("Can't delete the thread!"); } } while (1) { { wxCriticalSectionLocker enter(mbThreadCS); if (!mbThreadTCP...
by Ksawery
Fri Oct 18, 2019 12:54 pm
Forum: C++ Development
Topic: Delete thread with blocking function
Replies: 14
Views: 386

Delete thread with blocking function

I currently have a function to delete and clean up all my threads when the application is closed (i'm using 3 wxThreads). Unfortunately one of the threads uses a blocking function call for incoming TCP/IP communication. The function will not return until communication is established, so in the case ...
by Ksawery
Fri Oct 18, 2019 10:52 am
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

Ah, might be problem with a non-existent pointer...
by Ksawery
Fri Oct 18, 2019 10:44 am
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

I have a new issue, where my App crashes on triggering one of the events. On each itteration of my worker thread, I send events to one of the "main" windows, as well as an additional "diagnostics" window (which is tied to the same main window), under the condition that it is opened by the user: //Se...
by Ksawery
Thu Oct 17, 2019 1:43 pm
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

Sorry, turns out it was a simple error in not resetting a counter, and trying to access an invalid memory location. I will continue to test the application, hopefully it will work well now :)

Regards,
Ksawery
by Ksawery
Thu Oct 17, 2019 1:30 pm
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

The application now successfully compiles, but unfortunately crashes after 20 seconds or so, for some unknown reason. I seem to be getting different errors reported in the console each time. For example: corrupted double-linked list or (PomiarWiazki_Gateway:18974): GLib-GObject-[1;35mCRITICAL[0m **:...
by Ksawery
Thu Oct 17, 2019 12:10 pm
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

to make clean multithreading design you need blocking functions, and better blocking with timeout. do this Modbus library has any to read the data? or you are just polling modbus devices kinda to control their state or something? which lib are you using for modbus? I'm using the latest version of t...
by Ksawery
Thu Oct 17, 2019 12:06 pm
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

in simple words cMain has declared virtual method, but not implemented it. and there are no other implemented virtual methods in cMain. Thank you, this was it! I declared a virtual method that was meant to override a method in the wxThreadHelper class, but I removed all helper thread code from the ...
by Ksawery
Thu Oct 17, 2019 11:49 am
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

Here is the event table in cMain: wxBEGIN_EVENT_TABLE(cMain, wxFrame) EVT_COMMAND(wxID_ANY, wxEVT_RTU_UPDATE, cMain::OnModbusUpdate) EVT_BUTTON(10001, cMain::OnButtonClickedWsun) EVT_BUTTON(10002, cMain::OnButtonClickedWysun) EVT_BUTTON(10003, cMain::OnButtonClickedCalibrate) EVT_MENU(wxID_PREFERENC...
by Ksawery
Thu Oct 17, 2019 11:11 am
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

So i'm trying to implement the sending of custom events to my application windows from wxThreads. I'm using the following example for this purpose: https://wiki.wxwidgets.org/Inter-Thread_and_Inter-Process_communication#Sending_custom_events_to_the_main_thread After implementing this, I keep seeing ...
by Ksawery
Wed Oct 16, 2019 6:09 pm
Forum: C++ Development
Topic: "Main thread" vs. other threads
Replies: 30
Views: 754

Re: "Main thread" vs. other threads

Thanks for your replies. It does indeed seem that I occupied all available cores with the threads - and then some. So obviously my application worked very slowly. I'm new to multi-threading, so i'm still learning the best practices. I like the suggestion of sending events to the main thread, from th...