Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:05+00:00 2026-05-23T15:20:05+00:00

I have got a multi-threaded app that process a very large data file. Works

  • 0

I have got a multi-threaded app that process a very large data file. Works great on Window 7, the code is all C++, uses the pthreads library for cross-platform multi-threading. When I run it under Windows on my Intel i3 – Task manager shows all four cores pegged to the limit, which is what I want. Compiled the same code using g++ Ubuntu/VMWare workstation – same number of threads are launched, but all threads are running on one core (as far as I can tell – Task Manager only shows one core busy).

I’m going to dive into the pThreads calls – perhaps I missed some default setting – but if anybody has any idea, I’d like to hear them, and I can give more info –

Update: I did setup VMWare to see all four cores and /proc/cpuinfo shows 4 cores

Update 2 – just wrote a simple app to show the problem – maybe it’s VMWare only? – any Linux natives out there want to try and see if this actually loads down multiple cores? To run this on Windows you will need the pThread library – easily downloadable. And if anyone can suggest something more cpu intensive than printf- go ahead!

#ifdef _WIN32
#include "stdafx.h"
#endif
#include "stdio.h"
#include "stdlib.h"
#include "pthread.h"

void *Process(void *data)
{
   long id = (long)data;
   for (int i=0;i<100000;i++)
   {
      printf("Process %ld says Hello World\n",id);
   }
   return NULL;
}

#ifdef _WIN32
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, char* argv[])
#endif
{
   int numCores = 1;
   if (argc>1)
      numCores = strtol(&argv[1][2],NULL,10);
   pthread_t *thread_ids = (pthread_t *)malloc(numCores*sizeof(pthread_t));
   for (int i=0;i<numCores;i++)
   {
      pthread_create(&thread_ids[i],NULL,Process,(void *)i);
   }
   for (int i=0;i<numCores;i++)
   {
      pthread_join(thread_ids[i],NULL);
   }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:20:06+00:00Added an answer on May 23, 2026 at 3:20 pm

    I changed your code a bit. I changed numCores = strtol(&argv[1][2], NULL, 10); to numCores = strtol(&argv[1][0], NULL, 10); to make it work under Linux by calling ./core 4 maybe you where passing something in front of the number of cores, or because type _TCHAR is 3byte per char? Not that familiar with windows.. Further more since I wasn’t able to stress the CPU with only printf I also changed Process a bit.

    void *Process(void *data)
    {
         long hdata = (long)data;
         long id = (long)data;
         for (int i=0;i<10000000;i++)
         {
             printf("Process %ld says Hello World\n",id);
             for (int j = 0; j < 100000; j++)
             {
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   hdata *= j;
                   ...
             }
        }
    
        return (void*)hdata;
    }
    

    And now when I run gcc -O2 -lpthread -std=gnu99 core.c -o core && ./core 4 You can see that all 4 threads are running on 4 different cores well probably the are swapped from core to core at a time but all 4 cores are working overtime.

    core.c: In function ‘main’:
    core.c:75:50: warning: cast to pointer from integer of different size [-Wint-to-pointer-   cast]
    Starting 4 threads
    Process 0 says Hello World
    Process 1 says Hello World
    Process 3 says Hello World
    Process 2 says Hello World
    

    I verified it with htop hope it helps.. 🙂 I run dedicated Debian SID x86_64 with 4cores in case you’re wondering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following code from here to read an Excel file using
I have a multi-threaded app which is running under Linux 2.6.30 on an 8
I have got some code to load an assembly and get all types, which
I've got a highly multithreaded app written in Ruby that shares a few instance
I have an intermittent problem with some code that writes to a Windows Event
I really have a strange situation. I'm making a Linux multi-threaded C application using
I have a problem with CodeIgniter .htaccess file and hope that somebody can help
I have a new web app that is packaged as a WAR as part
suppose we have multi processor machine and multi threaded application. If two threads have
I'm currently developing a heavily multi-threaded application, dealing with lots of small data batch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.