- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, what is the fastest way of sending 32- or even 1-bit size data between two threads within a single multi--core CPU?
I tried shared variable and spin lock, it is about twenty times faster than a system semaphore, but still hundreds of cycles or more for a single data exchange.
volatile int buffer;
...
while(buffer != EMPTY) {
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
The nops appear to make it faster, I guess they reduce some congestion at the cost of very slight delays.
Any help?
Best regards,
Artur
I tried shared variable and spin lock, it is about twenty times faster than a system semaphore, but still hundreds of cycles or more for a single data exchange.
volatile int buffer;
...
while(buffer != EMPTY) {
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
The nops appear to make it faster, I guess they reduce some congestion at the cost of very slight delays.
Any help?
Best regards,
Artur
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's the fastest way. I.e. direct write in one thread, and spinning on load in another thread. Yes, it's hundreds of cycles, there is nothing you can do with that (if you need physical movement of data).
There is only 2 options to accelerate it. (1) Schedule both threads to the same core (no physical concurrency in this case), or (2) batch messages - you can physically transfer up to 64 bytes for the same cost.
Btw, you should use PAUSE instruction for spin loops instead of NOP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
nops tend to drag down the system, PAUSE is better. (I use PAUSE)
Under some special circumstances MONITOR/MWAIT may be better.
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page