How do I program for multi cores in Qt

Posted on 2011-05-09
Last Modified: 2012-05-11
I use RHEL 5 and QT 4.6.2. How do I program for multi cores that are available on my system. I would like to specify that thread 1 should always run on core 1 whereas thread 2 should always run on core 2 or something like that. Is this doable in RHEL or do I need a special RTOS?

Question by:rkreddy_kbs
    LVL 7

    Expert Comment

    There is no way in QT you can do this. May be you can try some other library where you can really acheive this or may be you can write your own C routine which can allow this.

    But Qt is not having any api or any thing which can does it unless you dont modify Qt srouce to do it.

    Author Comment

    Any suggestions for such a library - OpenMP ?
    LVL 7

    Expert Comment

    I am sorry, I am not aware of any such library,
    You know what it is kind of very difficult what you are tryiing to achieve because it is all OS Kernel which does this. this core thing of processor is all based on cycle stealing so only one way i can think to acheive via interrupt or some mechanism where you can come to know that One core is about to be finish thejob and there you can utilize the secod core.

    Well this is my best guess what I said above, but I think it is hard to have this thing at application level.

    Best of luck for your effort, and do let me know if you find some way of doing this
    LVL 12

    Accepted Solution

    You cannot do it by using QT only, because processor affinity is a very low level service provided by the O.S., so it cannot, for now, be provided by a cross platform library.
    You can use sched_setaffinity() call.
    As you can read from this page, cpu affinity is set on a thread group basis.
    So to bound a thread to only one (or a group of) cpu, you must pass the result of getid() as a pid (read the notes on this page).

    You can also use sched tools; this article explains how.

    Hope that helps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now