Click here to Skip to main content
15,893,381 members
Home / Discussions / C#
   

C#

 
GeneralRe: Read pdf file and write content in a doc file with images preserved Pin
Wendelius7-Jan-09 21:47
mentorWendelius7-Jan-09 21:47 
GeneralRe: Read pdf file and write content in a doc file with images preserved Pin
inzibharti7-Jan-09 22:26
inzibharti7-Jan-09 22:26 
GeneralRe: Read pdf file and write content in a doc file with images preserved Pin
Wendelius7-Jan-09 22:30
mentorWendelius7-Jan-09 22:30 
QuestionLockless Queue in C# slower than Locked Queue in C# Pin
Cyrilix6-Jan-09 20:52
Cyrilix6-Jan-09 20:52 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Luc Pattyn6-Jan-09 22:58
sitebuilderLuc Pattyn6-Jan-09 22:58 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Cyrilix6-Jan-09 23:28
Cyrilix6-Jan-09 23:28 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Luc Pattyn6-Jan-09 23:36
sitebuilderLuc Pattyn6-Jan-09 23:36 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Cyrilix7-Jan-09 1:18
Cyrilix7-Jan-09 1:18 
My internet was down for a little so I couldn't post right away.

public void Enqueue(T data)
{
    LockFreeQueueNode<T> tempTail = null;
    LockFreeQueueNode<T> tempTailNext = null;
    LockFreeQueueNode<T> newNode = new LockFreeQueueNode<T>(data);
    newNode.Data = data;
    do
    {
        tempTail = tail;
        tempTailNext = tempTail.NextNode;
        if (tempTail == tail)
        {
            if (tempTailNext == null)
            {
                // If the tail node we are referring to is really the last
                // node in the queue (i.e. its next node is null), then
                // try to point its next node to our new node
                //
                if (Interlocked.CompareExchange(ref tempTail.NextNode, newNode, tempTailNext) == tempTailNext)
                    break;
            }
            else
            {
                // This condition occurs when we have failed to update
                // the tail's next node. And the next time we try to update
                // the next node, the next node is pointing to a new node
                // updated by other thread. But the other thread has not yet
                // re-pointed the tail to its new node.
                // So we try to re-point to the tail node to the next node of the
                // current tail
                //
                Interlocked.CompareExchange(ref tail, tempTailNext, tempTail);
            }
        }
        Interlocked.Increment(ref retryCount);
    } while (true);

    // If we were able to successfully change the next node of the current tail node
    // to point to our new node, then re-point the tail node also to our new node
    //
    Interlocked.CompareExchange(ref tail, newNode, tempTail);
    Interlocked.Increment(ref count);
}


I believe this code was actually taken somewhere from a Codeproject article (but I happened to find it online from a different source). The part that's in bold is the important line that I added to measure the retry count, basically everytime we are unable to break out of the while loop and need to retry the operation again.
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Luc Pattyn7-Jan-09 1:58
sitebuilderLuc Pattyn7-Jan-09 1:58 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Daniel Grunwald7-Jan-09 2:37
Daniel Grunwald7-Jan-09 2:37 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Cyrilix7-Jan-09 9:02
Cyrilix7-Jan-09 9:02 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
ben.Kloosterman2-Feb-10 19:53
ben.Kloosterman2-Feb-10 19:53 
GeneralRe: Lockless Queue in C# slower than Locked Queue in C# Pin
Cyrilix3-Feb-10 7:40
Cyrilix3-Feb-10 7:40 
Questionconverting c header file in c# Pin
lawrenceinba6-Jan-09 20:31
lawrenceinba6-Jan-09 20:31 
AnswerRe: converting c header file in c# Pin
N a v a n e e t h6-Jan-09 20:48
N a v a n e e t h6-Jan-09 20:48 
AnswerRe: converting c header file in c# Pin
Guffa6-Jan-09 20:52
Guffa6-Jan-09 20:52 
GeneralRe: converting c header file in c# Pin
lawrenceinba6-Jan-09 20:59
lawrenceinba6-Jan-09 20:59 
GeneralRe: converting c header file in c# Pin
N a v a n e e t h6-Jan-09 21:14
N a v a n e e t h6-Jan-09 21:14 
GeneralRe: converting c header file in c# Pin
lawrenceinba6-Jan-09 21:19
lawrenceinba6-Jan-09 21:19 
GeneralRe: converting c header file in c# Pin
Dragonfly_Lee6-Jan-09 22:24
Dragonfly_Lee6-Jan-09 22:24 
GeneralRe: converting c header file in c# Pin
lawrenceinba6-Jan-09 22:35
lawrenceinba6-Jan-09 22:35 
GeneralRe: converting c header file in c# Pin
Dragonfly_Lee6-Jan-09 22:46
Dragonfly_Lee6-Jan-09 22:46 
AnswerRe: converting c header file in c# Pin
Rob Philpott6-Jan-09 23:00
Rob Philpott6-Jan-09 23:00 
GeneralRe: converting c header file in c# Pin
Luc Pattyn6-Jan-09 23:11
sitebuilderLuc Pattyn6-Jan-09 23:11 
GeneralRe: converting c header file in c# Pin
lawrenceinba6-Jan-09 23:27
lawrenceinba6-Jan-09 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.