Recent

Author Topic: Debian: SendMessage in a thread doesn't work  (Read 3195 times)

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
Debian: SendMessage in a thread doesn't work
« on: April 11, 2017, 10:23:05 am »
I have the same code in Linux and Windows (watch the attached files).

In Linux the SendMessage function leads to hangup of the project, works for the Windows application. Use of PostMessage solves all problems.

I would like to learn why?
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

balazsszekely

  • Guest
Re: Debian: SendMessage in a thread doesn't work
« Reply #1 on: April 11, 2017, 10:37:39 am »
SendMessage it's a blocking function, PostMessage on the other hand is asynchronous, you don't have to wait until the function is completed. 

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: Debian: SendMessage in a thread doesn't work
« Reply #2 on: April 11, 2017, 11:04:03 am »
@Getmem:
You may have added that this is cross-platform in the case of Lazarus.
To explain a bit more to OP: a sendmessage under windows is guaranteed to arrive.... at some point... - its just blocking a kernel thread - which has side effects that you can't oversee (program termination and the likes) A  postmessage can be ignored at all times. You really have to think hard about how you designed your program. FPC/Laz can't solve everything cross-platform.
« Last Edit: April 11, 2017, 11:10:32 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

balazsszekely

  • Guest
Re: Debian: SendMessage in a thread doesn't work
« Reply #3 on: April 11, 2017, 11:21:31 am »
Why use SendMessage/PostMessage in the first place? I would go with Synchronize/Queue. The only thing is missing from FPC is the possibility to pass vars/methods to Synchronize/Queue. Or perhaps it's already implemented in the trunk?

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
Re: Debian: SendMessage in a thread doesn't work
« Reply #4 on: April 11, 2017, 11:30:41 am »
Thanks, I know it. But why the SendMessage function in MSWindows doesn't cause hangup of the program, and in Linux such problem is available?  :o

p.s. In one of my projects in additional thread the splash-window is caused. In this thread I use SendMessage for sending of messages to a splash-window. Everything works at windows correctly, in Linux the splash-window isn't closed even after completion of thread.

The project is big. Therefore I try to make a test project to reproduce a problem.

Quote
Why use SendMessage/PostMessage in the first place?
I got used to use these methods  :-[
« Last Edit: April 11, 2017, 11:56:09 am by zoltanleo »
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: Debian: SendMessage in a thread doesn't work
« Reply #5 on: April 11, 2017, 12:02:41 pm »
Why use SendMessage/PostMessage in the first place? I would go with Synchronize/Queue. The only thing is missing from FPC is the possibility to pass vars/methods to Synchronize/Queue. Or perhaps it's already implemented in the trunk?
Hm.. basics: low-level threads allow pointer parameter... to a record that holds all information perhaps? Hm... starting to worry right now... hm... O:-)  Has always been there...

But in the case of TThread? Why isn't that there? I don't know what they were smoking (at Borland - well, I know  :-X - ) and why we copied that?

[the answer is struggling with hidden self, for intimi and ghosts of the past, anyway just a few will understand]
« Last Edit: April 11, 2017, 12:09:23 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

balazsszekely

  • Guest
Re: Debian: SendMessage in a thread doesn't work
« Reply #6 on: April 11, 2017, 12:10:37 pm »
Quote
Hm... starting to worry right now... hm... O:-)  Has always been there...
Probably we are talking about different things as usual  :D

 

TinyPortal © 2005-2018