Main Site Documentation

Question: What real-time programming constructs does .NET Micro Framework support


#1

In my opinion, the feature that really distinguishes .NET Micro Framework on FEZ products from other platforms like Arduino, Launchpad, BASIC STAMP/Propeller etc. is multithreading. I have very limited experience on .NET Framework, so please don’t mind if you think the question is too simple. And do reply, because I still need the answer :slight_smile:

Normally, in POSIX compliant operating systems, constructs like message queues and semaphores are available, which come really handy when doing multi-threading programming. What sort of comparative constructs are available in .NET Micro Framework? Are Semaphores, Mutexes and message queues avaialble? I can see Thread.Sleep() is available in .NET Micro Framework. But what about Mutex, Semaphore (seems like they’re available in .NET Framework; don’t know about .NET Micro) etc.? Is there a white paper or an article which discusses multithreading in .NET Micro Framework?


#2

.NET Micro Framework isn’t a real time development platform. Threading is simple, you can read any of the .NET articles on threading even if they don’t reference the Micro Framework, since it’s built off the same architecture it works exactly the same.

There are a lot of thread synchronization constructs in the .NET language, from simple lock() statements all the way to semaphores and sophisticated spin locks.


#3

Thanks for the quick answer. What about inter-thread communication (something comparable to message queues)? What should I look for?


#4

You can use global objects, and generic collections, but I don’t think there is any kind of message queuing in the micro framework. The full framework libraries have methods to send data to threads using the equivalent of a mailbox.

You just have to watch out with global objects that if you have multiple threads accessing them that you synchronize the access otherwise you can run into deadlocks and concurrency issues. You can create your own basic messaging system pretty easily using the generic collections.


#5

@ ASR

You can use .Net synchronization objects. Look inside System.Threading namespace:

http://msdn.microsoft.com/en-us/library/ee436582.aspx

Monitor, AutoResetEvent, ManualResetEvent are the ones you need for that.

William also has posted some good helpers classes on Fezzer.

http://www.fezzer.com/project/106/monitor2/
http://www.fezzer.com/project/107/blocking-queue/
http://www.fezzer.com/project/206/task-and-taskscheduler/
http://www.fezzer.com/project/133/stopwatch/
http://www.fezzer.com/project/105/semaphore-/

There are other members who have posted useful threading helpers as well.
Just search Fezzer using tag - “thread”.


#6

And Colin’s two recent posts:

http://blogs.msdn.com/b/netmfteam/archive/2011/01/17/threads-and-thread-priorities-in-netmf.aspx
http://blogs.msdn.com/b/netmfteam/archive/2011/02/01/thread-communication-and-synchronization.aspx


#7

[Edit] Somehow I did not see Arcitects post.
NETMF has the core constructs such as AutoResetEvent, ManualResetEvent, Monitor, and Interlocked. With those, you can build any other. In NETMF, no need for kernel mutex, as monitor handles that function. TMK, no native semaphore, but you can create one. Same for a concurrent queue for inter-thread sync. I have posted NETMF versions of some of the more useful classes here.


http://www.fezzer.com/project/206/task-and-taskscheduler/
http://www.fezzer.com/project/132/countdownevent/
http://www.fezzer.com/project/107/blocking-queue/
http://www.fezzer.com/project/106/monitor2/
http://www.fezzer.com/project/105/semaphore-/

However, non of these have much to do with real-time programming. These live in the concurrent programming space.


#8

We probably started at the same time. Anyways I have missed countdownevent in my list ;D


#9

I would like to add one more comment.
Although .NET Micro Framework in not a Real Time Operation system. GHI invented something called RLP (Run-time loadable procedures). This feature allows users to load native code (C/Assembly) for higher performance and real-time requirements.

RLP is an exclusive feature from GHI that you can enjoy in any NETMF solution made by GHI.


#10

Thanks everyone for all the information. It will take a while to digest all of it.