File: test_pthread_locale.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (54 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright 2017 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <emscripten/threading.h>
// This is really rather naughty, we shouldn't be including
// musl-internal headers like this.
#define weak __attribute__(__weak__)
#define hidden __attribute__((__visibility__("hidden")))
#include "pthread_impl.h"

#define NUM_THREADS  1

locale_t do_test() {
  pthread_t thread = pthread_self();
  locale_t loc = thread->locale;
  printf("  pthread_self() = %p\n", thread);
  printf("  pthread_self()->locale = %p\n", loc);

  if (!loc) {
    puts("ERROR: loc is null");
  }
  return loc;
}

void *thread_test(void *t) {
  puts("Doing test in child thread");
  pthread_exit((void*)do_test());
}

int main (int argc, char *argv[]) {
  puts("Doing test in main thread");
  locale_t main_loc = do_test();
  locale_t child_loc;

  if (emscripten_has_threading_support()) {
    long id = 1;
    pthread_t thread;

    pthread_create(&thread, NULL, thread_test, (void *)id);

    pthread_join(thread, (void**)&child_loc);
    assert(main_loc == child_loc);
  }

  return 0;
}