File: test_error.cpp

package info (click to toggle)
spglib 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,180 kB
  • sloc: ansic: 125,066; python: 7,717; cpp: 2,197; f90: 2,143; ruby: 792; makefile: 22; sh: 18
file content (22 lines) | stat: -rw-r--r-- 646 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <gtest/gtest.h>

#include <list>
#include <thread>

extern "C" {
#include "spglib.h"
void spg_set_error_code(SpglibError err);
}

TEST(Error, thread_safety) {
    auto thread_func = [](SpglibError err_val) {
        spg_set_error_code(err_val);
        // Small delay to make sure other thread has written
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
        ASSERT_EQ(spg_get_error_code(), err_val);
    };
    std::list<std::thread> thread_jobs{};
    thread_jobs.emplace_back(thread_func, SPGLIB_SUCCESS);
    thread_jobs.emplace_back(thread_func, SPGERR_NONE);
    for (auto &job : thread_jobs) job.join();
}