NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 50 51 52 53 54 … 93 Next »
Thread communication confusion

 
  • 0 Vote(s) - 0 Average
Thread communication confusion
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#1
2006-09-05, 08:54 PM
I probably should know how to do this but I've managed to wrap my brain in knots trying various things.

I have a situation where my main process thread creates a new thread that mostly sits around doing nothing until a specific time. At that point it needs to 'talk' to the main thread by passing some data so the main thread can act on it.

What's the best way to pass information back to the main thread in this way? I'm running myself round in circles. :confused:

Cheers,
Brian
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,626
Threads: 767
Joined: Nov 2003
#2
2006-09-05, 09:05 PM
Its not an easy question to answer. There are lots of ways of doing it.

I quite often use a Queue class with synchronized access to it. ie, main thread periodically polls for new object on the queue (locking access before checking, pulling object off the queue if present, then unlocking). The processing thread would lock the queue, place the object on the queue, then unlock the queue.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#3
2006-09-05, 09:18 PM
sub Wrote:Its not an easy question to answer. There are lots of ways of doing it.
LOL - I just wish I could find ONE that works. Smile

Quote:I quite often use a Queue class with synchronized access to it.
Thanks - I'll take a look to see if that works for me although I'm looking more for an event type of situation where the worker thread notifies the main thread immediately. I haven't had any luck with cross-thread eventing though - not sure if it's possible. I've also looked at async callbacks but I'm not sure if they're quite what I want either.

Cheers,
Brian
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,626
Threads: 767
Joined: Nov 2003
#4
2006-09-05, 09:44 PM
Is the main thread blocked waiting for the event to occur, or is it busy doing other stuff? If its not blocked, then I'm not sure you're going to find what you're looking for.
Old Dog
Offline

Posting Freak

Posts: 1,083
Threads: 99
Joined: Jul 2005
#5
2006-09-05, 10:32 PM (This post was last modified: 2006-09-05, 11:16 PM by Old Dog.)
You could define a custom Windows Message. Post the message from the worker and have a message handler in the main thread. But I wouldn't usually do it this way as I lack confidence in Window's main message queue.

What is the main thread doing when time lapses?

What will happen to the data?
Learning new tricks!
Visit Plain Jane's Collection
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#6
2006-09-05, 11:11 PM
The main process thread is a system service that does nothing but create other threads and is blocked by at least one of those threads being in existence.

It's the DVB Radio plugin/add-in that I've been working on over the past. I figured the only way to do this would be to have an ancillary service and talk to that service from a GB-PVR plugin that uses a TcpChannel to provide recording requests. The server-side of the TcpChannel is hosted by a listener thread spawned from the main service thread and I need the listener to tell the main thread that it has received a recording request/cancellation etc.

I don't want the listener to process the command/request directly - just identify what type it is and pass it back to the main thread so that it can act on it appropriately.

I'm not sure I have the model quite right in my head. Perhaps I need to go back to the drawing board. Smile

Cheers,
Brian
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#7
2006-09-05, 11:24 PM
Old Dog Wrote:You could define a custom Windows Message.
Yep - I thought about IPC but I'm trying to do this in what I see as a .NET / managed code sort of way. Windows messaging reminds me too much of the Win32 API and when I used to programme with C/C++ (the unmanaged variety). I figured there must be a cleaner way of doing this.

As I said in the previous post - the more I think about it the more I think I've got my model wrong.

This calls for my bean-bag, headphones, beer and heavy rock. Big Grin

Cheers,
Brian
23skidoo
Offline

Member

Posts: 120
Threads: 9
Joined: Sep 2006
#8
2006-09-15, 11:04 PM
A quick-and-dirty strategy that works in many situations is to declare static variables.

(EDIT: Thinking C++ and C# here. But I'm sure there's plenty of easy IPC stuff in the .Net framework (e.g. semaphores).

[Boy I'm late to the party. Bored. :-) ]
WinTV PVR-150 / ATI X1600 512 / 3GHz P4 / 2GB RAM
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Web Client: Slow with separate thread and date not obscured cncb 32 15,700 2016-10-10, 02:01 PM
Last Post: mvallevand
  CommunitySkin 4 Open development thread. Fatman_do 110 24,244 2008-12-14, 09:04 PM
Last Post: McBainUK
  Community Skin 3.0 Open development thread. Fatman_do 99 21,552 2007-07-30, 08:32 AM
Last Post: McBainUK
  Calender plugin - Early versions feedback thread McBainUK 44 12,077 2007-03-28, 10:14 PM
Last Post: McBainUK
  Gmail plugin - Beta test Thread McBainUK 39 11,704 2006-08-28, 03:25 AM
Last Post: skippy_nz
  getting back to the main thread? reven 1 1,509 2006-07-25, 08:18 AM
Last Post: reven
  Appearance Manager Documentation Thread. Fatman_do 14 6,020 2006-05-12, 05:18 PM
Last Post: Fatman_do

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode