Daily Archives

Articles indexed Tuesday April 27 2010

Page 6/121 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Lightweight spinlocks built from GCC atomic operations?

    - by Thomas
    I'd like to minimize synchronization and write lock-free code when possible in a project of mine. When absolutely necessary I'd love to substitute light-weight spinlocks built from atomic operations for pthread and win32 mutex locks. My understanding is that these are system calls underneath and could cause a context switch (which may be unnecessary for very quick critical sections where simply spinning a few times would be preferable). The atomic operations I'm referring to are well documented here: http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Atomic-Builtins.html Here is an example to illustrate what I'm talking about. Imagine a RB-tree with multiple readers and writers possible. RBTree::exists() is read-only and thread safe, RBTree::insert() would require exclusive access by a single writer (and no readers) to be safe. Some code: class IntSetTest { private: unsigned short lock; RBTree<int>* myset; public: // ... void add_number(int n) { // Aquire once locked==false (atomic) while (__sync_bool_compare_and_swap(&lock, 0, 0xffff) == false); // Perform a thread-unsafe operation on the set myset->insert(n); // Unlock (atomic) __sync_bool_compare_and_swap(&lock, 0xffff, 0); } bool check_number(int n) { // Increment once the lock is below 0xffff u16 savedlock = lock; while (savedlock == 0xffff || __sync_bool_compare_and_swap(&lock, savedlock, savedlock+1) == false) savedlock = lock; // Perform read-only operation bool exists = tree->exists(n); // Decrement savedlock = lock; while (__sync_bool_compare_and_swap(&lock, savedlock, savedlock-1) == false) savedlock = lock; return exists; } }; (lets assume it need not be exception-safe) Is this code indeed thread-safe? Are there any pros/cons to this idea? Any advice? Is the use of spinlocks like this a bad idea if the threads are not truly concurrent? Thanks in advance. ;)

    Read the article

  • Procedure/ Oracle

    - by DAVID
    How do you write a procedure which shows that one field's value cannot be higher than another field value, in terms of numbers... ive never done one before say. employee salary field cant be higher than his manager salary

    Read the article

  • c++ multithread

    - by chnet
    I use C++ to implement a thread class. My code shows in the following. I have a problem about how to access thread data. In the class Thread, I create a thread use pthread_create() function. then it calls EntryPoint() function to start thread created. In the Run function, I want to access the mask variable, it always shows segment fault. So, my question is whether the new created thread copy the data in original class? How to access the thread own data? class Thread { public: int mask; pthread_t thread; Thread( int ); void start(); static void * EntryPoint (void *); void Run(); }; Thread::Thread( int a) { mask =a; } void Thread::Run() { cout<<"thread begin to run" <<endl; cout << mask <<endl; // it always show segmentfault here } void * Thread::EntryPoint(void * pthis) { cout << "entry" <<endl; Thread *pt = (Thread *) pthis; pt->Run(); } void Thread::start() { pthread_create(&thread, NULL, EntryPoint, (void *)ThreadId ); pthread_join(thread, NULL); } int main() { int input_array[8]={3,1,2,5,6,8,7,4}; Thread t1(1); t1.start(); }

    Read the article

  • Splitting TIFF Files on different formats using .NET

    - by Jojo
    HI All, I have below code to extract a single page from a multi-paged TIFF file. The problem is, the input file is in CCITT Group 4 compression however the output compression is LZW. Can .NET outputs TIFF files other than this compression? FileStream fileStream = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite); sourceImage.SelectActiveFrame(firstFrameDimension, pageNumbers[i]); sourceImage.Save(fileStream, ImageFormat.Tiff); fileStream.Close();

    Read the article

  • Perl: remove relative path components?

    - by jnylen
    I need to get Perl to remove relative path components from a Linux path. I've found a couple of functions that almost do what I want, but: File::Spec->rel2abs does too little. It does not resolve ".." into a directory properly. Cwd::realpath does too much. It resolves all symbolic links in the path, which I do not want. Perhaps the best way to illustrate how I want this function to behave is to post a bash log where FixPath is a hypothetical command that gives the desired output: '/tmp/test'$ mkdir -p a/b/c1 a/b/c2 '/tmp/test'$ cd a '/tmp/test/a'$ ln -s b link '/tmp/test/a'$ ls b link '/tmp/test/a'$ cd b '/tmp/test/a/b'$ ls c1 c2 '/tmp/test/a/b'$ FixPath . # rel2abs works here ===> /tmp/test/a/b '/tmp/test/a/b'$ FixPath .. # realpath works here ===> /tmp/test/a '/tmp/test/a/b'$ FixPath c1 # rel2abs works here ===> /tmp/test/a/b/c1 '/tmp/test/a/b'$ FixPath ../b # realpath works here ===> /tmp/test/a/b '/tmp/test/a/b'$ FixPath ../link/c1 # neither one works here ===> /tmp/test/a/link/c1 '/tmp/test/a/b'$ FixPath missing # should work for nonexistent files ===> /tmp/test/a/b/missing

    Read the article

  • Replacement for rdoc usage

    - by Andrew Grimm
    According to this post, RDoc::usage is not currently available in ruby 1.9. Are there any good replacements available? I'd be interested to hear what's available from the standard install as well as what's available from gems.

    Read the article

  • Does Apple Magic Mouse fully work on Windows 7 x86/x64?

    - by Sorin Sbarnea
    I would like to know if Apple Magic Mouse works on Windows 7 (x86/x64) on non-Apple computers. Here are some checklists: x64 compatibility left click right click middle button? vertical scroll horizontal scroll bind additional gestures to keystrokes? are any usage problems? In case it works please advise on how to get the drivers.

    Read the article

  • User Productivity Kit - Powerful Packages (Part 2)

    - by [email protected]
    In my first post on packages I described what a package is and how it can be used. I also started explaining some of the considerations that should be taken into account when determining how to arrange your packages. The first is when the files are interrelated and depend on one another such as an HTML file and it's graphics. A second consideration is how the files are used in your outlines. Let's say you're using a dozen Word doc files. You could place them all in a single package or put each Word doc file in a separate package but what's the right thing to do? There are several factors that will influence your decision. To understand the first, let me explain a function of UPK publishing. Take an outline in UPK that has an attachment (concept, frame link, or hyperlink) that points to a file in a package. When you publish this outline, the publishing engine will determine that there is a link to a file in the package and copy the contents of the package to the publishing destination directory. This is done to ensure that any interrelated files are kept together. For the situation where you have an HTML file with links to number of graphics files, this is a good thing. If, however, the package has a dozen unrelated Word doc files and you link to only one of them, all dozen Word documents will be copied to the publishing destination directory.  Whether or not this is a good thing is dependent on two things. First, are all of the files in the package used in the outline that you're publishing? Take an outline that includes links to all of the Word documents in that dozen document package I described earlier. For this situation, you may choose to keep all the files in a single package for convenience. A second consideration is how your organization leverages reuse in UPK. In this context, I'm referring to the link style of reuse such as when you link to the same topic from multiple UPK outlines and changes to the topic appear in both places. Take an example where you have the earlier mentioned dozen Word document package and an outline with a dozen topics in it. Each topic has an attachment pointing to one of the Word documents in the package (frame link, concept, etc.) If you're only publishing this outline, the single package probably works fine but what if you're reusing one of these topics in another outline? As I explained earlier, linking to one file in the package will result in all files in the package being copied to your published output. In this example, linking to one topic in the first outline will result in all dozen Word documents being copied to the published output. This may result in files in the output that you don't want there for business or size reasons. This is a situation in which you should consider placing each of the Word documents in it's own separate package. With each document in it's own package, that link to a single document will result in only that single package and single Word document being copied to the published output. In my last post I had described that packages are documents in the UPK library. When using the multi-user version of the UPK Developer you can leverage standard library capabilities for managing the files in these packages during the development process - capabilities such as check in / check out, history, etc. When structuring your packages take into consideration how the authors are going to be adding, modifying and deleting files from the packages. A single package is a single document in the UPK library. Like any other document in the library, a single user can check out the package and edit it at a time. If you have a large number of files in a single package and these must be modified by many users, you need to consider whether this will cause problems as multiple users compete to update the same package. If the files don't depend on each other consider placing the files in separate packages to reduce contention. I hope you've enjoyed these two posts on how you can leverage the power of packages in your content. In summary, consider the following when structuring your packages: Is the asset a single, standalone file or a set of files that depend on each other? Will all the files always be used together in a single outline or may only some of the files be needed based on how the content is reused across multiple outlines? Will multiple developers need to update the files in a single package or should you break it into multiple packages to reduce contention when checking out the document? We'd like to hear from you on how you're using packages in your content. Please add your comments below! Thank you and I hope these two posts have given you additional insights into how to use packages in your content and structure them for efficient use. John Zaums Senior Director, Product Development Oracle User Productivity Kit

    Read the article

  • Background positioning - CSS

    - by Kevin
    Please see attached screenshot The background is a bit off in both IE and chrome (although it was working before? hence the exact numbers??), although in ffox it looked allright.. Here is the code for what I thought was very straight forward... am I missing something? #wrapper{ width:100%; overflow:hidden; position:relative; background:url(../images/body-bg.jpg) no-repeat ; background-position: -20px top; } And an IE fix #wrapper{ background-position: -21px top; }

    Read the article

  • PHP 5.3 and '::'

    - by Lee
    Hello, I started into PHP with 5.3 and am using the '::' to access constants ex; class::const. However, when I try to use my code in an older PHP namely 5.1.6 and 5.2.12, I get an error that the '::' is unexpected. How do I access constants in these older versions of PHP5?

    Read the article

  • send variable fancybox onclick event

    - by samuel saul
    hi, i want to send href value. but its not working. function display () { $.fancybox({ 'href': 'index.php', 'width' : '75%', 'height' : '75%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' }); } i tryed this : function display (who) { $.fancybox({ 'href': 'index.php'+who, 'width' : '75%', 'height' : '75%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' }); } <a onclick="javascript:display("?id=11");" href="#" >create</a> this onclick event inside the innerhtml so its not working with '' why

    Read the article

  • python script to download xml files on my server

    - by Blankman
    I need a python script that will do the following: connect to a URL, and that URL will return a number like 1200. Use the number, to download xml files named: 1 to x where x is the number from #1. store the files in a particular directory. Sorry I've never written a python script, so if you could guide me along that would be great (maybe with a some comments). I will be running this as a cron job if that matters.

    Read the article

  • How to use the debugger with nested static libraries in XCode?

    - by EightyEight
    Hi all, A project that I've inherited has the following structure: Project A produces a static library. Project B produces a static library and links with library A. Project C produces the executable and links with library B. When I run app in debug mode, I can successfully debug code within the executable (project C) and the static library from project B. I can't, however, debug anything in the Project A library -- my breakpoints are ignored. I've checked and made sure that debug symbols are enabled and not stripped. Is there something else I'm missing? Thanks

    Read the article

  • Routing zend request through a default controller when controller not found.

    - by Brett Pontarelli
    Below is a function defined in my Bootstrap class. I must be missing something fundamental in the way Zend does routing and dispatching. What I am trying to accomplish is simple: For any request /foo/bar/* that is not dispatchable for any reason try /index/foo/bar/. The problem I'm having is when the FooController exists I get Action "foo" does not exist. Basically, the isDispatchable is always false. public function run() { $front = Zend_Controller_Front::getInstance(); $request = $front->getRequest(); $dispatcher = $front->getDispatcher(); //$controller = $dispatcher->getControllerClass($request); if (!$dispatcher->isDispatchable($request)) { $route = new Zend_Controller_Router_Route( ':action/*', array('controller' => 'index') ); $router = $front->getRouter(); $router->addRoute('FallBack', $route); } $front->dispatch(); }

    Read the article

  • Javascript: Using the Module Pattern for larger projects

    - by Rob
    I'm interested in using the Module Pattern to better organize my future projects. Unfortunately, there are only a few brief tutorials and proof-of-concept examples of the Module Pattern. Using the module pattern, I would like to organize projects into this sort of structure: project.arm.object.method(); Where "project" is my global project name, "arm" is a sub-section or branch of the project, "object" is an individual object, and so on to the methods and properties. However, I'm not sure how I should be declaring and organizing multiple "arms" and "objects" under "project". var project = window.project || {}; project.arm = project.arm || {}; project.arm.object = (function() { var privateVar = "Private contents."; function privateMethod() { alert(privateVar); } return { method: privateMethod }; }()); Are there any best practices or conventions when defining a complex module structure? Should I just declare a new arm/object underneath the last?

    Read the article

  • JTree events seem misordered

    - by MeBigFatGuy
    It appears to me that tree selection events should happen after focus events, but this doesn't seem to be the case. Assume you have a JTree and a JTextField, where the JTextField is populated by what is selected in the tree. When the user changes the text field, on focus lost, you update the tree from the text field. however, the tree selection is changed before the focus is lost on the text field. this is incorrect, right? Any ideas? Here is some sample code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Focus extends JFrame { public static void main(String[] args) { Focus f = new Focus(); f.setLocationRelativeTo(null); f.setVisible(true); } public Focus() { Container cp = getContentPane(); cp.setLayout(new BorderLayout()); final JTextArea ta = new JTextArea(5, 10); cp.add(new JScrollPane(ta), BorderLayout.SOUTH); JSplitPane sp = new JSplitPane(); cp.add(sp, BorderLayout.CENTER); JTree t = new JTree(); t.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent tse) { ta.append("Tree Selection changed\n"); } }); t.addFocusListener(new FocusListener() { public void focusGained(FocusEvent fe) { ta.append("Tree focus gained\n"); } public void focusLost(FocusEvent fe) { ta.append("Tree focus lost\n"); } }); sp.setLeftComponent(new JScrollPane(t)); JTextField f = new JTextField(10); sp.setRightComponent(f); pack(); f.addFocusListener(new FocusListener() { public void focusGained(FocusEvent fe) { ta.append("Text field focus gained\n"); } public void focusLost(FocusEvent fe) { ta.append("Text field focus lost\n"); } }); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

    Read the article

  • How to get index using LINQ?

    - by codymanix
    Given a datasource like that: var c = new Car[] { new Car{ Color="Blue", Price=28000}, new Car{ Color="Red", Price=54000}, new Car{ Color="Pink", Price=9999}, // .. }; How can I find the index of the first car satisfying a certain condition with LINQ? EDIT: I could think of something like this but it looks horrible: int firstItem = someItems.Select((item, index) => new { ItemName = item.Color, Position = index }).Where(i => i.ItemName == "purple") .First() .Position; Will it be the best to solve this with a plain old loop?

    Read the article

  • LoadClip problem

    - by Mango
    Hi, i have a loadClip problem. appears in the movie in the final stage, not do the movie animation. Any Tip? appears in the film as the final stage, not so animation var imageListener:Object = new Object(); var imageLoader:MovieClipLoader = new MovieClipLoader(); imageLoader.addListener(imageListener); imageLoader.loadClip("handsketch_animation.swf", pages_cont); stop();

    Read the article

  • IBM Websphere MQ Server alternatives

    - by I Clark
    Are there any alternatives to IBM Websphere MQ Server for Windows? We need to access a remote Queue Manager that doesn't support client connections (only Queue Manager to Queue Manager). I've noticed that there are some BizTalk Host Integration adapters but they only seem to behave as clients (one transactional, the other non-transactional).

    Read the article

  • What is the general process of web hosting?

    - by ggfan
    I want to upload my site public so people can use it. I am currently using a free PHP webhosting company that supports up to a certian amount. When sites that say they offer unlimited upload, data, etc for like $10/month, is that all you need to run a big site? Or how do I host a big site, if it gets popular?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >