Threading

  • Thread starter Thread starter Aleksei Guzev
  • Start date Start date
A

Aleksei Guzev

Greetings!

1. Can I join (or something like) to all the threads in the ThreadPool?
2. Does a thread have messages queue. I mean the queue like in Win32. If it
does, can one write code to access the queue (Post, Send, GetMessage).
3. Will some synchronization primitives be implemented in future versions of
..NET? Semaphores, for example. Or one should implement them manually via
monitors?

Aleksei Guzev
 
Dave said:
1. no
2. no. A .net thread is not the same as an OS thread.
3. There are lots of sample code out there that implements semaphores.
Here's one...

http://www.ironringsoftware.com/DesktopDefault.aspx?PageId=16

Thank You very much. There are some good books on parallel programming.
Perhaps if you described what you are trying to accomplish we can offer some
suggestions.

I am implementing a message based system. Earlier I wrote such systems using
Win32 threads. Now I try writing for .NET. I tried to port old algorithms on
the platform. It's clear that I have to build a new algorithm. Seems like I
should manually create message queues blocking reading threads while they
(queues) are empty. It's easy enough. Is there another aproach?

Aleksei Guzev
 
Aleksei Guzev wrote:
|| Greetings!
||
|| 1. Can I join (or something like) to all the threads in the
|| ThreadPool?
|| 2. Does a thread have messages queue. I mean the queue like in
|| Win32. If it does, can one write code to access the queue (Post,
|| Send, GetMessage).
|| 3. Will some synchronization primitives be implemented in future
|| versions of .NET? Semaphores, for example. Or one should implement
|| them manually via monitors?
||
|| Aleksei Guzev

1. No.
2. Win32 threads and mesage queues are two different things. If you want access to the windows message queue you need to pump
messages and a "Window ". (remember messages are send to "Windows" only). So, if you need to get Windows messages in your managed
application you have to create a Form in your thread using Application.Start(...).
3. The .NET way is to use Monitors.

Willy.
 
I am implementing a message based system. Earlier I wrote such systems using
Win32 threads. Now I try writing for .NET. I tried to port old algorithms on
the platform. It's clear that I have to build a new algorithm. Seems like I
should manually create message queues blocking reading threads while they
(queues) are empty. It's easy enough. Is there another aproach?

From your description it isn't clear to me what your system requirements
are. A message based system can mean many things. The mechanisms you need to
use will vary widely based on considerations such as whether this is all
within the same process, across multiple processes, across machine
boundaries, what the timing constraints and requirements are, etc.

That being said you might want to look at the ReaderWriterLock
synchronization classes. It may be a good starting point for you.
 
See inline ****
Aleksei Guzev wrote:
|| ||| Aleksei Guzev wrote:
||||| Greetings!
|||||
||||| 1. Can I join (or something like) to all the threads in the
||||| ThreadPool?
||||| 2. Does a thread have messages queue. I mean the queue like in
||||| Win32. If it does, can one write code to access the queue (Post,
||||| Send, GetMessage).
||||| 3. Will some synchronization primitives be implemented in future
||||| versions of .NET? Semaphores, for example. Or one should implement
||||| them manually via monitors?
|||||
||||| Aleksei Guzev
|||
||| 1. No.
||| 2. Win32 threads and mesage queues are two different things. If you
||| want
|| access to the windows message queue you need to pump
||| messages and a "Window ". (remember messages are send to "Windows"
||| only).
|| So, if you need to get Windows messages in your managed
||
|| That is not true. Message queue is created once thread code calls a
|| function from gdi or user32. Thus creating a window is sufficient,
|| but is not nesessary.
||

****
No you are wrong, I'm talking about managed code here. How would you call GDI or user32 functions from managed code, and what
functions would you call from user32 that creates a message queue (CreateWindow() perhaps??).
Furthermore you need to pump messages, creating a window is not sufficient.


|| Aleksei Guzev
||
||| application you have to create a Form in your thread using
||| Application.Start(...).
||| 3. The .NET way is to use Monitors.
|||
||| Willy.
 
Willy, you're wrong, Alex is right. Messages in Win32 API can be sent to
threads without a window. "remember messages are sent to windows only" is
just not true.

Jerry

Willy Denoyette said:
See inline ****
||| 2. Win32 threads and mesage queues are two different things. If you
||| want
|| access to the windows message queue you need to pump
||| messages and a "Window ". (remember messages are send to "Windows"
||| only).
|| So, if you need to get Windows messages in your managed
||
|| That is not true. Message queue is created once thread code calls a
|| function from gdi or user32. Thus creating a window is sufficient,
|| but is not nesessary.
||

****
No you are wrong, I'm talking about managed code here. How would you call
GDI or user32 functions from managed code, and what
 
Richard,
I'm sorry, but to me a message-only window is still a "window". I know it's not visible has no Z-order etc. but you have to call
RegisterClassEx and CreateWindowEx in order to create one; or you need to change an existing "regular" window into a message-only
window by calling SetParent with HWND_MESSAGE as hWndNewParent.

But again my point was how do you create a message-only window from managed code without PInvoking Win32 API's like CreateWindowEx
and SetParent.

Willy.
 
I'm sorry I don't know the answer to your question, just want to clarify
that I wasn't talking about message only windows, you can send messages
between threads without a window.

Can't you use other form of communicating? Like named pipes, IP connections
and so on?

Jerry

Willy Denoyette said:
Richard,
I'm sorry, but to me a message-only window is still a "window". I know
it's not visible has no Z-order etc. but you have to call
RegisterClassEx and CreateWindowEx in order to create one; or you need to
change an existing "regular" window into a message-only
window by calling SetParent with HWND_MESSAGE as hWndNewParent.

But again my point was how do you create a message-only window from
managed code without PInvoking Win32 API's like CreateWindowEx
and SetParent.

Willy.


"Richard Grimes [MVP]" <read my sig> wrote in message news:%[email protected]...
 
Jerry III said:
I'm sorry I don't know the answer to your question, just want to clarify
that I wasn't talking about message only windows, you can send messages
between threads without a window.

But OP (Alex) was talking about Windows messages.
About what messages are you talking then? Please specify the class/method from the FCL you are using for this.

Willy.
 
Back
Top