public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Pthread-win32 races?
@ 2006-12-12 12:27 Sergey Fokin
  2006-12-13  8:39 ` Ross Johnson
  2006-12-20  2:08 ` Ross Johnson
  0 siblings, 2 replies; 6+ messages in thread
From: Sergey Fokin @ 2006-12-12 12:27 UTC (permalink / raw)
  To: pthreads-win32

Hi all.

I have some peculiarities with pthread-win32 and suppose there's a bug
in library.

Here's my example code:

#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <assert.h>

void * thr(void * arg)
{
  sem_post((sem_t*)arg);
  return 0;
}

int main()
{
    sem_t sem;
    int error = 0;
    error = sem_init(&sem, 0, 0); // OK
    assert(!error);

    pthread_t thread;
    error = pthread_create(&thread, 0, thr, &sem); // OK
    assert(!error);

    sem_wait(&sem);
    error = sem_destroy(&sem);
    if (error != 0)
    {
        error = errno; // errno == 16 (EBUSY)
        printf("errno = %d\n", error);
    }

    pthread_join(thread, 0);

    return error;
}


So, here we have error 16 (0x10) in almost all runs, independently on
compile options (at least i couldn't find working combination).
Compiler is msvc 7.1 sp1.

I've read about some troubles with it in BUGS file, but first, this
one is unrelated to those, as I can see, second all tests from `tests'
directory run with no errors, but this one fails even with same
compile options.

When I've tried to debug, it turned out that when main() is executing
sem_destroy(), child thread is still in sem_post(). But I couldn't
find out what's going on there and supposed this is some kind of race,
this is why subject is about races.

Google didn't find similar issues about pthread-win32 library.

Really hope, this is my fault, but I have no idea where I'm wrong.

Thanks in advance.

PS I'll also try gcc for win32 and msvc8.0 later - I don't have them
on this computer.

-- 
eof

^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: Pthread-win32 races?
@ 2006-12-12 20:12 Ye Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Ye Liu @ 2006-12-12 20:12 UTC (permalink / raw)
  To: Sergey Fokin, pthreads-win32

Can I be removed from the mail list?

Thanks,

Liu Ye 

-----Original Message-----
From: pthreads-win32-owner@sourceware.org
[mailto:pthreads-win32-owner@sourceware.org] On Behalf Of Sergey Fokin
Sent: Tuesday, December 12, 2006 4:27 AM
To: pthreads-win32@sourceware.org
Subject: Pthread-win32 races?

Hi all.

I have some peculiarities with pthread-win32 and suppose there's a bug
in library.

Here's my example code:

#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <assert.h>

void * thr(void * arg)
{
  sem_post((sem_t*)arg);
  return 0;
}

int main()
{
    sem_t sem;
    int error = 0;
    error = sem_init(&sem, 0, 0); // OK
    assert(!error);

    pthread_t thread;
    error = pthread_create(&thread, 0, thr, &sem); // OK
    assert(!error);

    sem_wait(&sem);
    error = sem_destroy(&sem);
    if (error != 0)
    {
        error = errno; // errno == 16 (EBUSY)
        printf("errno = %d\n", error);
    }

    pthread_join(thread, 0);

    return error;
}


So, here we have error 16 (0x10) in almost all runs, independently on
compile options (at least i couldn't find working combination).
Compiler is msvc 7.1 sp1.

I've read about some troubles with it in BUGS file, but first, this one
is unrelated to those, as I can see, second all tests from `tests'
directory run with no errors, but this one fails even with same compile
options.

When I've tried to debug, it turned out that when main() is executing
sem_destroy(), child thread is still in sem_post(). But I couldn't find
out what's going on there and supposed this is some kind of race, this
is why subject is about races.

Google didn't find similar issues about pthread-win32 library.

Really hope, this is my fault, but I have no idea where I'm wrong.

Thanks in advance.

PS I'll also try gcc for win32 and msvc8.0 later - I don't have them on
this computer.

--
eof

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-12-20  2:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-12 12:27 Pthread-win32 races? Sergey Fokin
2006-12-13  8:39 ` Ross Johnson
2006-12-13  9:26   ` Sergey Fokin
2006-12-13 14:26     ` Ross Johnson
2006-12-20  2:08 ` Ross Johnson
2006-12-12 20:12 Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).