Considerations for a 'mailbox' class

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Considerations for a 'mailbox' class

Post by Jorg » Wed May 04, 2005 1:47 pm

Hi guys,

Yesterday I found back something I was looking for, for a long time. A while back I designed a mailbox class that is a x-thread manager for object interaction. It has the following features:

- Threads can wait for mail by assigning themselves. When they wait infinite, they will get a signal (and being woken up again) when mail arrives for the thread that waits
- Threads can wait for a selected time, after a time-out the proc simply returns with an error

The mailbox keeps track of all objects, which can even have a life-time and are deleted when not being taken out within a certain period of time, or ofcourse can stay in there for an infinite time.

This mechanism will significantly help thread programmers by offering object / data decoupling, threads can wait for messages and take up no CPU time while waiting (signals and timed signals are used).

I found this code, and it is for pthreads. I would like to know how much of pthreads is used in Windows (this code is originally linux). The concern I have is the thread signaling and broadcasting (e.g. when the maibox gets destroyed, all waiting threads must exit their wait loop).

Anybody knows how much of pthreads is portable? I want to donate this class to wxWidgets eventually (called wxThreadMailBox) ..

The great thing about this class is that is has been tested with 10 threads all talking to eachother with this one MailBox. There was a diagnostic thread, network thread, draw thread, GPS calculation thread, etc. It worked like a charm.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

ddaeschl
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Oct 27, 2004 6:06 pm
Location: Western NY
Contact:

Post by ddaeschl » Fri May 06, 2005 9:08 pm

Hi Jorg,

The win32 API provides a rich set of lock/wait objects such as Mutexes, Semaphores, and Events (condition variable like). Most of these objects are very much like their posix counterparts...

Therefore, there are many solutions to posix on win32, and a couple are listed below.

http://sources.redhat.com/pthreads-win32/
http://www.microsoft.com/windowsservers ... fault.mspx

- Dave

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Fri May 06, 2005 11:29 pm

Thanks Dave,

When I find time, I can look if I can convert this class to a wxWidgets class .. :-)


Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply