public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Memory Barriers at pthread using CYGWIN
@ 2023-06-08 14:29 Mümin A.
  2023-06-08 14:37 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2023-06-09  1:44 ` Duncan Roe
  0 siblings, 2 replies; 6+ messages in thread
From: Mümin A. @ 2023-06-08 14:29 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 140 bytes --]

Hi,

I wrote a simple test for pthread_barrier_wait. it won't work as expected.

result should be

r1 = 1, r2 = 1

Thanks,
Mümin

[-- Attachment #2: CMakelists.txt --]
[-- Type: text/plain, Size: 295 bytes --]

cmake_minimum_required(VERSION 3.26)

project(test)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


add_definitions(-D__POSIX_VISIBLE=200112 -D_POSIX_C_SOURCE=200112)

add_executable(test main.cpp)

target_link_libraries(test pthread)

[-- Attachment #3: main.cpp --]
[-- Type: text/plain, Size: 738 bytes --]

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

int x = 0;
int y = 0;
int r1 = 0;
int r2 = 0;

pthread_barrier_t barrier;

void* thread1(void* arg) {
    y = 1;
    pthread_barrier_wait(&barrier);  // Memory barrier
    r1 = x;
    return NULL;
}

void* thread2(void* arg) {
    x = 1;
    pthread_barrier_wait(&barrier);  // Memory barrier
    r2 = y;
    return NULL;
}

int main() {
    pthread_t t1, t2;

    pthread_barrier_init(&barrier, NULL, 2);

    pthread_create(&t1, NULL, thread1, NULL);
    pthread_create(&t2, NULL, thread2, NULL);

    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    printf("r1 = %d, r2 = %d\n", r1, r2);

    pthread_barrier_destroy(&barrier);

    return 0;
}

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

* RE: [EXTERNAL] Memory Barriers at pthread using CYGWIN
  2023-06-08 14:29 Memory Barriers at pthread using CYGWIN Mümin A.
@ 2023-06-08 14:37 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2023-06-08 22:58   ` Mümin A.
  2023-06-09  1:44 ` Duncan Roe
  1 sibling, 1 reply; 6+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2023-06-08 14:37 UTC (permalink / raw)
  To: Mümin A., cygwin

> result should be
> 
> r1 = 1, r2 = 1
>

And what was the result you saw?

Anton Lavrentiev
Contractor NIH/NLM/NCBI


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

* Re: [EXTERNAL] Memory Barriers at pthread using CYGWIN
  2023-06-08 14:37 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
@ 2023-06-08 22:58   ` Mümin A.
  2023-06-09  0:19     ` Kevin Schnitzius
  2023-06-09  0:22     ` Takashi Yano
  0 siblings, 2 replies; 6+ messages in thread
From: Mümin A. @ 2023-06-08 22:58 UTC (permalink / raw)
  To: Lavrentiev, Anton (NIH/NLM/NCBI) [C], cygwin

[-- Attachment #1: Type: text/plain, Size: 653 bytes --]

r1=0 and r2=0
That is my result with Cygwin on windows. It’s false.

When I compiled with gcc. The result is correct but when I use lasted Cygwin gcc in windows 10. The result is false.


Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] <lavr@ncbi.nlm.nih.gov>
Sent: Thursday, June 8, 2023 5:37:31 PM
To: Mümin A. <muminaydin06@gmail.com>; cygwin@cygwin.com <cygwin@cygwin.com>
Subject: RE: [EXTERNAL] Memory Barriers at pthread using CYGWIN

> result should be
>
> r1 = 1, r2 = 1
>

And what was the result you saw?

Anton Lavrentiev
Contractor NIH/NLM/NCBI


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

* Re: [EXTERNAL] Memory Barriers at pthread using CYGWIN
  2023-06-08 22:58   ` Mümin A.
@ 2023-06-09  0:19     ` Kevin Schnitzius
  2023-06-09  0:22     ` Takashi Yano
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Schnitzius @ 2023-06-09  0:19 UTC (permalink / raw)
  To: cygwin

On Thursday, June 8, 2023 at 06:59:53 PM EDT, Mümin A. via Cygwin <cygwin@cygwin.com> wrote:

>
> r1=0 and r2=0
> That is my result with Cygwin on windows. It’s false.
> 
> When I compiled with gcc. The result is correct but when I use lasted Cygwin gcc in windows 10. The result is false.


> cmake .
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.26 or higher is required.  You are running version 3.25.3



> g++ main.cpp
>./a
r1 = 1, r2 = 1



Kevin

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

* Re: Memory Barriers at pthread using CYGWIN
  2023-06-08 22:58   ` Mümin A.
  2023-06-09  0:19     ` Kevin Schnitzius
@ 2023-06-09  0:22     ` Takashi Yano
  1 sibling, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2023-06-09  0:22 UTC (permalink / raw)
  To: cygwin; +Cc: Mümin A.

On Thu, 8 Jun 2023 22:58:59 +0000
Mümin A. wrote:
> r1=0 and r2=0
> That is my result with Cygwin on windows. It’s false.
> 
> When I compiled with gcc. The result is correct but when I use lasted Cygwin gcc in windows 10. The result is false.

I cannot reproduce your problem.

If I compile main.cpp with 'g++ main.cpp', a.exe outputs
r1 = 1, r2 = 1

If I use cmake, I get an error message:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.26 or higher is required.  You are running version 3.25.3

My environment is:
cygwin 3.4.6
g++ (GCC) 11.4.0
cmake version 3.25.3

all packages are updated.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

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

* Re: Memory Barriers at pthread using CYGWIN
  2023-06-08 14:29 Memory Barriers at pthread using CYGWIN Mümin A.
  2023-06-08 14:37 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
@ 2023-06-09  1:44 ` Duncan Roe
  1 sibling, 0 replies; 6+ messages in thread
From: Duncan Roe @ 2023-06-09  1:44 UTC (permalink / raw)
  To: cygwin

On Thu, Jun 08, 2023 at 05:29:59PM +0300, cygwin wrote:
> Hi,
>
> I wrote a simple test for pthread_barrier_wait. it won't work as expected.
>
> result should be
>
> r1 = 1, r2 = 1
>
> Thanks,
> Mümin

> cmake_minimum_required(VERSION 3.26)
>
> project(test)
>
> set(CMAKE_CXX_STANDARD 14)
> set(CMAKE_CXX_STANDARD_REQUIRED ON)
> set(CMAKE_CXX_EXTENSIONS OFF)
>
>
> add_definitions(-D__POSIX_VISIBLE=200112 -D_POSIX_C_SOURCE=200112)
>
> add_executable(test main.cpp)
>
> target_link_libraries(test pthread)

> #include <stdio.h>
> #include <pthread.h>
>
> int x = 0;
> int y = 0;
> int r1 = 0;
> int r2 = 0;
>
> pthread_barrier_t barrier;
>
> void* thread1(void* arg) {
>     y = 1;
>     pthread_barrier_wait(&barrier);  // Memory barrier
>     r1 = x;
>     return NULL;
> }
>
> void* thread2(void* arg) {
>     x = 1;
>     pthread_barrier_wait(&barrier);  // Memory barrier
>     r2 = y;
>     return NULL;
> }
>
> int main() {
>     pthread_t t1, t2;
>
>     pthread_barrier_init(&barrier, NULL, 2);
>
>     pthread_create(&t1, NULL, thread1, NULL);
>     pthread_create(&t2, NULL, thread2, NULL);
>
>     pthread_join(t1, NULL);
>     pthread_join(t2, NULL);
>
>     printf("r1 = %d, r2 = %d\n", r1, r2);
>
>     pthread_barrier_destroy(&barrier);
>
>     return 0;
> }

WFFM (compiled as a C program)

Cheers ... Duncan.

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

end of thread, other threads:[~2023-06-09  1:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 14:29 Memory Barriers at pthread using CYGWIN Mümin A.
2023-06-08 14:37 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-06-08 22:58   ` Mümin A.
2023-06-09  0:19     ` Kevin Schnitzius
2023-06-09  0:22     ` Takashi Yano
2023-06-09  1:44 ` Duncan Roe

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).