Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Implementing barrier in linux assembly
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Melzzzzz  
View profile  
 More options Oct 3 2012, 8:03 pm
Newsgroups: alt.lang.asm, comp.programming.threads
From: Melzzzzz <m...@zzzzz.com>
Date: Thu, 4 Oct 2012 02:03:04 +0200
Local: Wed, Oct 3 2012 8:03 pm
Subject: Implementing barrier in linux assembly
I have implemented barrier in Linux, with simple
approach.
Struct barrier has num threads, count thread entered
in barrier and thread mutex to protect barrier operation.
When thread enters it first acquires mutex then
decreases count . If count is zero it resets counter ,goes to
wake all threads that wait, then releases mutex.
In other case releases mutex and goes to wait.

This works ok except that if several threads
enter barrier, it can happen that waking thread
wakes before some thread(s) enter syscall.
Then, of course, program hangs.
I have solved this with nanosleep syscall,
so that waking thread sleeps for one microsecond
before issuing futex wake syscall.
Is there simpler solution without sleeping?
Eg futex does not waits if edx variable does not
match variable that rdi points to.
But this I haven't tried as don't know
when to reset variable.
So for now I use sleeping method.

Thanks

struc barrier num{
        .count dd num
        .num dd num
        .mutex dd 0

}

virtual at 0
        oBarrier barrier 0
end virtual

macro futex_barrier barrier{
        local .L0, .L1
        mov r15,barrier
        acquire r15 + oBarrier.mutex
        dec dword[r15 + oBarrier.count]
        jz .L0
        release r15 + oBarrier.mutex
        mov eax, 202
        lea rdi, [r15 + oBarrier.num]
        mov rsi, FUTEX_WAIT or FUTEX_PRIVATE_FLAG
        mov edx, [r15 + oBarrier.num]
        xor r10,r10
        syscall
        jmp .L1
.L0:
        sys_nanosleep myspec
;       mov rdi,msgwake
;       xor eax,eax
;       call printf
        mov eax,[r15 + oBarrier.num]
        mov [r15 + oBarrier.count],eax
        mov edx,eax
        mov eax,202
        lea rdi, [r15 + oBarrier.num]
        mov rsi, FUTEX_WAKE or FUTEX_PRIVATE_FLAG
        syscall
        release r15 + oBarrier.mutex
.L1:

}

macro acquire sema{
        local .L0
        mov ebx,1
.L0:
        xor eax,eax
        lock cmpxchg [sema],ebx
        test eax,eax
        jnz .L0

}

macro release sema{
        lock and dword[sema],0


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »