Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Threading, how many threads simultaneously?
« previous next »
  • Print
Pages: [1]

Author Topic: Threading, how many threads simultaneously?  (Read 1461 times)

Offline pablito

  • Member
  • *
  • Posts: 5
Threading, how many threads simultaneously?
« on: February 10, 2010, 08:30:17 AM »
Hi,
I'm developing some drum plugin for rockbox, it is nearly ready for release, but we heave encountered difficulties regarding threading on rockbox when the plugin is run on the machine (simulator is OK).

I have wrote some tests to check some utilities in the plugin, so actually the real plugin will not be so resource consuming. But anyway my questions are:
- how many threads can be created in rockbox?
- is it possible to run threads exit repeatedly?

I have the following code, which stops in the assertion at the end (implemented as splash message). It seems that only 3 threads were actually running. Am I doing something wrong? The actual value of the variable 'counter' in the end is 30000. This was running on iRiver H340.

// code excerpt
static int counter = 0;
static struct mutex mtx;
static long stack1[DEFAULT_STACK_SIZE];
static long stack2[DEFAULT_STACK_SIZE];
static long stack3[DEFAULT_STACK_SIZE];
static long stack4[DEFAULT_STACK_SIZE];
static long stack5[DEFAULT_STACK_SIZE];

static
void do_something( void )
{
   unsigned max;
   for ( max = 0; max < 10000; max++ ) {
      rb->mutex_lock(&mtx);
      counter ++;
      rb->mutex_unlock(&mtx);
   }

   rb->thread_exit();
}

void test_mutex( void )
{
  rb->mutex_init(&mtx);

  unsigned thread1;
  unsigned thread2;
  unsigned thread3;
  unsigned thread4;
  unsigned thread5;

  thread1 = rb->create_thread(do_something, stack1, sizeof(stack1), 0, "test1" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  thread2 = rb->create_thread(do_something, stack2, sizeof(stack2), 0, "test2" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  thread3 = rb->create_thread(do_something, stack3, sizeof(stack3), 0, "test3" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  thread4 = rb->create_thread(do_something, stack4, sizeof(stack4), 0, "test4" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  thread5 = rb->create_thread(do_something, stack5, sizeof(stack5), 0, "test5" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  rb->thread_wait(thread1);
  rb->thread_wait(thread2);
  rb->thread_wait(thread3);
  rb->thread_wait(thread4);
  rb->thread_wait(thread5);

  /* this is to test that the mutex has protected the variable */
  assert( counter == 50000 );
}

Logged

Offline torne

  • Developer
  • Member
  • *
  • Posts: 994
  • arf arf
Re: Threading, how many threads simultaneously?
« Reply #1 on: February 10, 2010, 08:53:25 AM »
You can't create that many threads, no. The maximum number of threads on a swcodec target with recording (like your h340) is 17, but most of those are already used by the system threads. There are only 2-3 spare slots (the plugin's main thread doesn't take a slot because plugin code by default runs in the already-existing UI thread), so you can't create more than 2-3 more threads.

create_thread will return NULL when there is no room to create another thread, so you should be checking that.
Logged
some kind of ARM guy. ipodvideo/gigabeat-s/h120/clipv2. to save time let's assume i know everything.

Offline pablito

  • Member
  • *
  • Posts: 5
Re: Threading, how many threads simultaneously?
« Reply #2 on: February 10, 2010, 09:27:14 AM »
OK, thanks for figuring out.

p.f.
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Threading, how many threads simultaneously?
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.065 seconds with 15 queries.