Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to get number of active threads in C ?

Reply
Thread Tools

How to get number of active threads in C ?

 
 
Marc-André Cournoyer
Guest
Posts: n/a
 
      04-16-2008
Hi all,

I'm writing a Ruby C extension and I need a fast way to get the number
of active threads. I got something working for 1.8.6 but it's not
portable to other Ruby version like 1.9 (because I can't include the
header for rb_thread_t struct and the like) and it doesn't look very
sane.

Here's my code for Ruby 1.8.6:

#include "node.h"
...

rb_thread_t mainth = (rb_thread_t) RDATA(rb_thread_main())->data;
rb_thread_t th = mainth;
size_t num_threads = 0;

do {
th = th->next;
if (th->status != THREAD_KILLED)
num_threads ++;
} while (th != mainth);

printf("%d active threads\n", num_threads);

I'm wondering if there's a better way to do this. I know there's the
rb_thread_list, but I would like to avoid creating a new Ruby Array on
each call.

Any suggestion?
thx,
Marc

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Find number of active threads lmbutler Python 0 10-16-2008 02:56 PM
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
Get number of threads in JVM Crouchez Java 10 09-01-2007 08:27 PM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM



Advertisments