Sponsored Content
Special Forums UNIX and Linux Applications High Performance Computing Memory Barriers for (Ubuntu) Linux (i686) Post 302430449 by gorga on Thursday 17th of June 2010 03:48:05 PM
Old 06-17-2010
Quote:
Originally Posted by Corona688
Small world, how so? Smilie
Noting your help on the Programming forum too!

Quote:
I think you're overreacting... Any memory I/O monopolizes the bus*, LOCK just guarantees one instruction gets two ops in a row.
Are you suggesting then, that if I used such an instruction relatively frequently (say once in a loop of maybe a 100 execution statements, per core), I shouldn't notice a significant drop in throughput of the application?

Quote:
I'm not sure LOCK XCGH even forces a real memory fetch anymore(might be simple to test, try to get back to you on that.)
You'd expect that each core accessing the XCHG variable though would have to get the value from memory though as soon as it accessed it, otherwise what use would CMPXCHG be? Not sure about this area to be honest, (but I read that these atomic operations do create a memory barrier so a core cannot execute instructions either side of said barrier out of order).

Quote:
Lastly, if you're doing no mutexing, what are you doing instead -- polling? That's not going to be more efficient, untold amounts of CPU will be expended on what amounts to a while(1) loop.
What I'm building is a thread-pool with n pthreads equal to the number of cores (so I am using pthreads). The pthreads continually execute a list of "lightweight tasks". The user can create tasks and send "messages" between them. (If you've ever used Erlang, something similar to the abstraction provided there but in my case using C).

The pthreads occasionally check the "value" of a task "state", when they reach that task in the queue, therefore if the "state" isn't "ready" they simply move on to the next task (hence the pthread has more work to do and isn't polling continuously). You see what this means, as long as a pthread "eventually" discovers a task is "ready" that's okay, even if it's not asap. It seems like a lock would be unnecessary here then, but a pthread shouldn't detect that the task state is "ready" before its other data members have been updated (hence the need for a memory barrier).

If using these atomic operations isn't going to impact throughput, then great they solve the problem, but even that seems like overkill when I only need to ensure that a handful of statements are executed in a certain order.
 

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Memory-waste in Ubuntu/Debian?

I have 512 mem on this laptop, though 'top' tells me I only have 380. However, Ubuntu is using 288 mb of memory, when I only have 3 terminals, running lynx, vim(for this file) and (of course) top. Considering it I have lynx running a 600 page txt file, which of course would eat some memory but 300?... (0 Replies)
Discussion started by: riwa
0 Replies

2. Linux

i686, x86 64, ppc

Hi, i am quite new to linux. I am interested in fedora linux distro. Fedora Project I dont know which one to choose, either i686, x86 64 or ppc. I prefer a live cd, coz its easy to use. And what is the difference between "Fedora Desktop Live Media" and "Fedora KDE Live Media". (3 Replies)
Discussion started by: superblacksmith
3 Replies

3. Programming

Getting the total virtual memory for ubuntu in c++

Hi guys , i need to get the total virtual memory in ubuntu but i need to write a C++ code for that, any idea on how to go about doing it? any references? or website that i can refer to ? (6 Replies)
Discussion started by: xiaojesus
6 Replies

4. Ubuntu

XP and Linux (Ubuntu) on same disk, Can I install Ubuntu on not-yet partitioned portion of disk?

My PC (Esprimo, 3 yeas old) has one hard drive having 2 partitions C: (80 GB NTFS, XP) and D: (120 GB NTFS, empty) and and a 200 MB area that yet is not-partitioned. I would like to try Ubuntu and to install Ubuntu on the not-partitioned area . The idea is to have the possibility to run... (7 Replies)
Discussion started by: C.Weidemann
7 Replies
RRDTHREADS(1)							      rrdtool							     RRDTHREADS(1)

NAME
rrdthreads - Provisions for linking the RRD library to use in multi-threaded programs SYNOPSIS
Using librrd in multi-threaded programs requires some extra precautions, as the RRD library in its original form was not thread-safe at all. This document describes requirements and pitfalls on the way to use the multi-threaded version of librrd in your own programs. It also gives hints for future RRD development to keep the library thread-safe. Currently only some RRD operations are implemented in a thread-safe way. They all end in the usual ""_r"" suffix. DESCRIPTION
In order to use librrd in multi-threaded programs you must: o Link with librrd_th instead of librrd (use "-lrrd_th" when linking) o Use the ""_r"" functions instead of the normal API-functions o Do not use any at-style time specifications. Parsing of such time specifications is terribly non-thread-safe. o Never use non *"_r" functions unless it is explicitly documented that the function is tread-safe. o Every thread SHOULD call "rrd_get_context()" before its first call to any "librrd_th" function in order to set up thread specific data. This is not strictly required, but it is the only way to test if memory allocation can be done by this function. Otherwise the program may die with a SIGSEGV in a low-memory situation. o Always call "rrd_error_clear()" before any call to the library. Otherwise the call might fail due to some earlier error. NOTES FOR RRD CONTRIBUTORS Some precautions must be followed when developing RRD from now on: o Only use thread-safe functions in library code. Many often used libc functions aren't thread-safe. Take care in the following situations or when using the following library functions: o Direct calls to "strerror()" must be avoided: use "rrd_strerror()" instead, it provides a per-thread error message. o The "getpw*", "getgr*", "gethost*" function families (and some more "get*" functions) are not thread-safe: use the *"_r" variants o Time functions: "asctime", "ctime", "gmtime", "localtime": use *"_r" variants o "strtok": use "strtok_r" o "tmpnam": use "tmpnam_r" o Many others (lookup documentation) o A header file named rrd_is_thread_safe.h is provided that works with the GNU C-preprocessor to "poison" some of the most common non- thread-safe functions using the "#pragma GCC poison" directive. Just include this header in source files you want to keep thread-safe. o Do not introduce global variables! If you really, really have to use a global variable you may add a new field to the "rrd_context" structure and modify rrd_error.c, rrd_thread_safe.c and rrd_non_thread_safe.c o Do not use "getopt" or "getopt_long" in *"_r" (neither directly nor indirectly). "getopt" uses global variables and behaves badly in a multi-threaded application when called concurrently. Instead provide a *_r function taking all options as function parameters. You may provide argc and **argv arguments for variable length argument lists. See "rrd_update_r" as an example. o Do not use the "rrd_parsetime" function! It uses lots of global variables. You may use it in functions not designed to be thread-safe, like in functions wrapping the "_r" version of some operation (e.g., "rrd_create", but not in "rrd_create_r") CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS Currently there exist thread-safe variants of "rrd_update", "rrd_create", "rrd_dump", "rrd_info", "rrd_last", and "rrd_fetch". AUTHOR
Peter Stamfest <peter@stamfest.at> 1.4.3 2008-06-08 RRDTHREADS(1)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy