Re: gthread: how many cores do I have?



On 15 March 2010 11:36, Tor Lillqvist <tml iki fi> wrote:
>> int g_thread_get_cores( void );
>
> Well, firstly the function name should use "processors" and not
> "cores". But I think that in general such a function would be too
> simplistic, and just look at things from the perspective of the
> current low end of the market.

You're right, it is rather low-level, but it's at about the same level
as glib's threadpool API, for example:

GThreadPool*        g_thread_pool_new                   (GFunc func,
                                                         gpointer user_data,
                                                         gint max_threads,
                                                         gboolean exclusive,
                                                         GError **error);

The call I'm suggesting would give you the maximum useful value for
the max_threads parameter: the maximum number of concurrent threads
you can run before you stop seeing a speedup.

How about:

   int g_thread_get_processors( void );

> multiprocessing etc. (Note, I am certainly not an expert here.) You
> will almost certainly need some platform-dependent code, surely? Or
> use other libraries that already do it for you?

My library is just built on pthreads (or these days, g_thread()).

At the moment it defaults to 1 if you run it at the command-line (if
you are running on a server it's rude to take all resources unless
given permission) and 4 if you run it from a GUI (a desktop user will
typically want to give a large chunk of their machine to a program).
The "4" isn't very good and I'd like to improve that.

John


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]