pthread_mutex_t mutex;
-static void* thread1_fun(void* ignore)
+static void* thread_fun(void* val)
{
pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex);
- fprintf(stderr, "The first thread is terminating.\n");
- return NULL;
-}
-static void* thread2_fun(void* ignore)
-{
- pthread_mutex_lock(&mutex);
- pthread_mutex_unlock(&mutex);
-
- fprintf(stderr, "The second thread is terminating.\n");
+ fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
return NULL;
}
{
pthread_mutex_init(&mutex, NULL);
- pthread_t thread1, thread2;
- pthread_create(&thread1, NULL, thread1_fun, NULL);
- pthread_create(&thread2, NULL, thread2_fun, NULL);
+ int id[2] = {0, 1};
+ pthread_t thread1;
+ pthread_t thread2;
+ pthread_create(&thread1, NULL, thread_fun, (void*)&id[0]);
+ pthread_create(&thread2, NULL, thread_fun, (void*)&id[1]);
fprintf(stderr, "All threads are started.\n");
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
$ ./pthread-mutex-simple
> [0.000000] [sthread/INFO] Starting the simulation.
-> The first thread is terminating.
+> The thread 0 is terminating.
> All threads are started.
-> The second thread is terminating.
+> The thread 1 is terminating.
> User's main is terminating.
> [0.000000] [sthread/INFO] All threads exited. Terminating the simulation.
\ No newline at end of file
sthread_mutex_t mutex;
-static void* thread1_fun(void* ignore)
-{
- sthread_mutex_lock(&mutex);
- sthread_mutex_unlock(&mutex);
-
- return NULL;
-}
-static void* thread2_fun(void* ignore)
+static void* thread_fun(void* ignore)
{
sthread_mutex_lock(&mutex);
sthread_mutex_unlock(&mutex);
{
sthread_mutex_init(&mutex, NULL);
- sthread_t thread1, thread2;
- sthread_create(&thread1, NULL, thread1_fun, NULL);
- sthread_create(&thread2, NULL, thread2_fun, NULL);
- // pthread_join(thread1, NULL);
- // pthread_join(thread2, NULL);
+ sthread_t thread1;
+ sthread_t thread2;
+ sthread_create(&thread1, NULL, thread_fun, NULL);
+ sthread_create(&thread2, NULL, thread_fun, NULL);
+ sthread_join(thread1, NULL);
+ sthread_join(thread2, NULL);
fprintf(stderr, "done\n");
return 0;
} else if (siginfo->si_signo == SIGSEGV) {
fprintf(stderr, "Segmentation fault.\n");
#if HAVE_SMPI
- if (smpi_enabled() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
+ if (SMPI_is_inited() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
#if HAVE_PRIVATIZATION
fprintf(stderr, "Try to enable SMPI variable privatization with --cfg=smpi/privatization:yes.\n");
#else
if (XBT_LOG_ISENABLED(mc_client, xbt_log_priority_debug))
kernel::EngineImpl::get_instance()->display_all_actor_status();
#if HAVE_SMPI
- XBT_DEBUG("Smpi_enabled: %d", (int)smpi_enabled());
- if (smpi_enabled())
+ XBT_DEBUG("Smpi_enabled: %d", SMPI_is_inited());
+ if (SMPI_is_inited())
SMPI_finalize();
#endif
}
XBT_PRIVATE void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
size_t buff_size);
-XBT_PRIVATE int smpi_enabled();
XBT_PRIVATE double smpi_mpi_wtime();
XBT_PRIVATE void smpi_mpi_init();
/* nothing done in this version */
}
-int smpi_enabled() {
- return MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED;
-}
-
static void smpi_init_papi()
{
#if HAVE_PAPI
return smpi_exit_status;
}
-static bool smpi_inited = false;
int SMPI_is_inited()
{
- return smpi_inited;
+ return MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED;
}
+
// Called either directly from the user code, or from the code called by smpirun
void SMPI_init(){
smpi_init_options_internal(false);
}
smpi_init_papi();
smpi_check_options();
- smpi_inited = true;
}
void SMPI_finalize()
XBT_LOG_NEW_DEFAULT_CATEGORY(sthread, "pthread intercepter");
namespace sg4 = simgrid::s4u;
-static sg4::Host* lilibeth = NULL;
+static sg4::Host* lilibeth = nullptr;
int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**))
{
sthread_disable();
}
-int sthread_create(unsigned long int* thread, const /*pthread_attr_t*/ void* attr, void* (*start_routine)(void*),
+int sthread_create(unsigned long int* thread, const void* /*pthread_attr_t* attr*/, void* (*start_routine)(void*),
void* arg)
{
static int TID = 0;
if (SMPI_is_inited())
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
- char name[100];
- sprintf(name, "%d:%d", rank, TID);
- sg4::ActorPtr actor = sg4::Actor::init(name, lilibeth);
+ std::string name = simgrid::xbt::string_printf("%d:%d", rank, TID);
+ sg4::ActorPtr actor = sg4::Actor::init(name.c_str(), lilibeth);
actor->start(thread_create_wrapper, start_routine, arg);
intrusive_ptr_add_ref(actor.get());
*thread = reinterpret_cast<unsigned long>(actor.get());
return 0;
}
-int sthread_join(sthread_t thread, void** retval)
+int sthread_join(sthread_t thread, void** /*retval*/)
{
sg4::ActorPtr actor(reinterpret_cast<sg4::Actor*>(thread));
actor->join();
return 0;
}
-int sthread_mutex_init(sthread_mutex_t* mutex, const /*pthread_mutexattr_t*/ void* attr)
+int sthread_mutex_init(sthread_mutex_t* mutex, const void* /*pthread_mutexattr_t* attr*/)
{
auto m = sg4::Mutex::create();
intrusive_ptr_add_ref(m.get());
*/
static void xbt_preinit() XBT_ATTRIB_CONSTRUCTOR(200);
static void xbt_postexit();
-void sthread_enable() {} // These symbols are used from ContextSwapped in any case, but they are only useful
-void sthread_disable() {} // when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
+void sthread_enable()
+{ // These symbols are used from ContextSwapped in any case, but they are only useful
+}
+void sthread_disable()
+{ // when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
+}
#ifdef _WIN32
#include <windows.h>
{
return false;
}
-#endif
\ No newline at end of file
+#endif
e.load_platform(platform_file);
simgrid::s4u::Actor::create("actor", e.host_by_name("c1_0"), runner);
e.run();
- }
- catch (simgrid::AssertionError& e) {
+ } catch (const simgrid::AssertionError& e) {
std::cout << e.what() << "\n";
}