#2423 closed enhancement (fixed)

rtems_iterate_over_all_threads lacks user callback private pointer pass through

Reported by: Jeffrey Hill Owned by:
Priority: normal Milestone: 5.1
Component: unspecified Version: 4.10
Severity: normal Keywords: rtems_iterate_over_all_threads callback private
Cc: Blocked By:


Typically when designing an API that calls a user callback there is a user private "void *" pointer transparently passed through to the user callback so that the user can access his private state inside of his callback without being forced to employ a global variable. A global variable doesnt work very well if there are multiple objects instances created each of them using the same method with rtems_iterate_over_all_threads. This type of "void *" private pointer is of course a standard approach allowing the users callback to behave much the same way as a virtual method in C++, but nevertheless retaining a compatible C based API.

An enhanced version of the API might look like this.

void rtems_iterate_over_all_threads_xxx(
rtems_per_thread_routine routine, void * const pUserPrivatePassThrogh

typedef void (*rtems_per_thread_routine_xxx)(
Thread_Control *the_thread, void * const pUserPrivatePassThrogh

The pUserPrivatePassThrogh is not used by the library; it is retained for the duration of the rtems_iterate_over_all_threads_xxx function only so that it can be passed through to the user's callback.

thanks for your consideration of this matter

Change History (9)

comment:1 Changed on 09/22/15 at 15:35:30 by Jeffrey Hill

PS: I am using rtems_iterate_over_all_threads to implement a task mode, thread aware, Ethernet connected GDB stub. When GDB attaches it stops certain threads and sends their status depending on its operating modes, but this of course should not apply to the GDB communication threads. Therefore there needs to be a way to iterate through all of the threads checking each of them to determine if they are tagged as being GDB stop-mode immune.

comment:2 Changed on 09/22/15 at 20:02:27 by Jeffrey Hill

PPS: In thread.h and iterateoverthreads.c one could create some code like this. A possible implementation.

/ This defines the type for a method which operates on a single thread.


typedef void (*rtems_per_thread_routine)( Thread_Control * );
typedef void (*rtems_per_task_function)( Thread_Control *,

void * const pUserPrivate );


  • This routine iterates over all threads regardless of API and
  • invokes the specified routine. */

void rtems_iterate_over_all_threads(

rtems_per_thread_routine routine


void rtems_thread_per_each_callback(rtems_per_task_function pFunction,

void * const pUserPrivate );

void rtems_thread_per_each_callback(rtems_per_task_function pFunction,

void * const pUserPrivate )


uint32_t i;
uint32_t api_index;
Thread_Control *the_thread;
Objects_Information *information;

if ( !pFunction )


for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {

if ( !_Objects_Information_table[ api_index ] )


information = _Objects_Information_table[ api_index ][ 1 ];
if ( !information )


for ( i=1 ; i <= information->maximum ; i++ ) {

the_thread = (Thread_Control *)information->local_table[ i ];

if ( !the_thread )






comment:3 Changed on 09/22/15 at 20:07:16 by Jeffrey Hill

Ok, yes, the names I choose are pretty lame.

comment:4 Changed on 10/31/16 at 12:38:33 by Sebastian Huber


comment:5 Changed on 11/02/16 at 08:13:53 by Sebastian Huber <sebastian.huber@…>

In d271c3bb78f86dd9417a964b019b8e38911064fa/rtems:

rtems: Add rtems_task_iterate()

Update #2423.

comment:6 Changed on 11/02/16 at 08:14:03 by Sebastian Huber <sebastian.huber@…>

In 4cf58905b825ea8d2b9d677dc32d529390052d3a/rtems:

cpuuse: Use rtems_task_iterate()

Update #2423.

comment:7 Changed on 12/14/16 at 14:25:44 by Sebastian Huber

Resolution: fixed
Status: newclosed

Documentation update done.

comment:8 Changed on 05/11/17 at 07:31:02 by Sebastian Huber


comment:9 Changed on 11/09/17 at 06:27:14 by Sebastian Huber


Milestone renamed

Note: See TracTickets for help on using tickets.