Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Threading in Netduino2


  • Please log in to reply
4 replies to this topic

#1 xmen

xmen

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 29 January 2015 - 03:47 AM

I have a I2C LCD that needs to be updated rapidly, the problem is that. If I write in LCD from a separate Thread it is very slow, but if I write from main thread. Its like 10 times faster. I even set the Thread.Priority to Highest but it doesn't effect anything. And if I start a thread with Highest priority and write from main thread. Main thread is more slower(I think its priory is normal)

 

What I know about threading is that each thread gets 20ms time slice on each iteration. So if I2C is writing in 40ms, that means it has to wait 20ms x n threads to complete its write. Thats why it is slow ? Seems to me that I should avoid Threads if I need speed.

 

 

Am I missing something ?



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 31 January 2015 - 09:22 AM

Hi xmen,

Try to keep threads asleep unless they are actively doing something.

Do you have any "spinning loops" occupying 100% of MCU?

Chris

#3 xmen

xmen

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 31 January 2015 - 11:46 AM

Hi xmen,

Try to keep threads asleep unless they are actively doing something.

Do you have any "spinning loops" occupying 100% of MCU?

Chris

Hi Chris,

 

I did try with Thread.Sleep(1000) in main thread loop. Didn't get any difference.



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 February 2015 - 02:41 PM

Hi xmen,

Do you only have two threads running (main, sleeping...and the I2C thread)?

In theory both threads should have the same priority.

In the end...do what works well. But if you're seeing strange behavior and we can reproduce it consistently, let's pull Microsoft into the conversation for a potential NETMF vNext performance boost.

Chris

#5 xmen

xmen

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 02 February 2015 - 03:35 PM

Hi xmen,

Do you only have two threads running (main, sleeping...and the I2C thread)?

In theory both threads should have the same priority.

In the end...do what works well. But if you're seeing strange behavior and we can reproduce it consistently, let's pull Microsoft into the conversation for a potential NETMF vNext performance boost.

Chris

Hi Chris,

 

I just realized and remember that main thread has inner hidden loop(in another class) which I was unaware of. And the main thread was never actually sleeping. Anyways, I now use Single Threaded app, works better. And I try to avoid Thread.Sleep at all cost.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.