public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* PTHREAD_MUTEX_SHARED on Cygwin
@ 2021-01-09 18:23 Thomas Koenig
  2021-01-09 19:58 ` Brian Inglis
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Thomas Koenig @ 2021-01-09 18:23 UTC (permalink / raw)
  To: cygwin

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


Hi,

there is a branch of gfortran for implementing coarrays based on a
shared memory implementation instead of MPI, the devel_coarray/native
branch.

I tried it out on Cygwin, but it doesn't work there (hangs on the
first sync).

The branch uses pthread mutexes and condition variables
with PTHREAD_PROCESS_SHARED for synchronization between processes.

I also ran the attached test program, which gave the output

pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)failed: No error


Is it correct that PTHREAD_PROCESS_SHARED is not supported on
Cygwin?  Is it supported for condition variables, or is the fact
that it is reported as working an oversight?

If PTHREAD_PROCESS_SHARED does not work, are there known workarounds?

Best regards

	Thomas

[-- Attachment #2: s.c --]
[-- Type: text/x-csrc, Size: 971 bytes --]

#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>

#define ERR_CHK(x) \
  do { \
	if (x) { \
	  perror(#x "failed"); \
	  exit(1); \
	} \
  } while (0)

int
main(int argc, char **argv) {
  pthread_condattr_t cattr;
  pthread_mutexattr_t mattr;
  pthread_mutex_t *m;
  pthread_cond_t *c;
  void *mem;

  ERR_CHK((mem = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED);

  m = mem;
  c = mem + 0x800;

  ERR_CHK(pthread_mutexattr_init(&mattr));
  ERR_CHK(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED));
  ERR_CHK(pthread_mutex_init(m, &mattr));
  ERR_CHK(pthread_mutexattr_destroy(&mattr));

  ERR_CHK(pthread_condattr_init(&cattr));
  ERR_CHK(pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED));
  ERR_CHK(pthread_cond_init(c, &cattr));
  ERR_CHK(pthread_condattr_destroy(&cattr));

  printf("Success\n");

  return 0;
}

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

end of thread, other threads:[~2021-01-11  7:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09 18:23 PTHREAD_MUTEX_SHARED on Cygwin Thomas Koenig
2021-01-09 19:58 ` Brian Inglis
2021-01-09 22:16   ` PTHREAD_PROCESS_SHARED not implemented (was PTHREAD_MUTEX_SHARED on Cygwin) Brian Inglis
2021-01-09 22:54     ` Brian Inglis
2021-01-11  7:01     ` Noel Grandin
2021-01-09 20:24 ` PTHREAD_MUTEX_SHARED on Cygwin Marco Atzeri
2021-01-10 19:40 ` Thomas Koenig

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