CPU usage

  • Thread starter madmike159
  • Start date
  • #1
madmike159
Gold Member
369
0

Main Question or Discussion Point

My laptop has a duel core Intel Centrino processor. Whenever I write programs in C/C++ in Visual Studio and run programs which should execute at full speed only one core seems to be doing anything. Some programs seem to be able to make full use of both cores, is this possible in Visual Studio?
 

Answers and Replies

  • #2
560
1
You need to learn to use "threads".

Each core is logically a different processor and will always be executing something different from the other. Since your code is only ever doing one thing at a time, there is only work for one processor. Threads allow you to "do two things at once" so that the other processor has something to do. Note, multithreading is a large and complex subject, there are several things you will need to learn to do it properly and not all tasks can be multithreaded.
 
  • #3
madmike159
Gold Member
369
0
Ok thanks. For the kind of program I was talking about threads won't be necessary.
 
  • #4
rcgldr
Homework Helper
8,690
521
I made an example multi-threaded program for Visual Studio C/C++. It just copies a file, using one thread to read the source file, and a second thread to write the copy. It shows how to: create threads, use mutexes, use semapahores, use waitformultipleobjects(), and implements linked list fifo messaging used for inter-thread communication (the list elements contain ptrs to buffers and counts). Waitformultipleobject(), is a nice feature, it allows a thread to make a single atomic (non-interruptable) call to the system, to get ownership of a fifo (mutex), and wait for non-zero count (semaphore), and decrement the fifo count (semaphore), eliminating any thread priority issues. The setup is a bit complicated, but the actual thread code is very simple.

http://rcgldr.net/misc/mtcopy.zip
 
Last edited:

Related Threads on CPU usage

  • Last Post
Replies
6
Views
2K
  • Last Post
2
Replies
48
Views
3K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
8
Views
6K
  • Last Post
Replies
1
Views
6K
  • Last Post
Replies
1
Views
3K
Replies
1
Views
2K
  • Last Post
Replies
9
Views
2K
Replies
9
Views
3K
Replies
12
Views
4K
Top