target_link_libraries(pthread-${x} PRIVATE Threads::Threads)
add_dependencies(tests pthread-${x})
+ ADD_TESH_FACTORIES(pthread-${x} "^thread" --setenv LD_PRELOAD=${CMAKE_BINARY_DIR}/lib/libsthread.so --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
endif()
-# set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
+ set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
+
endforeach()
# Regular sthread examples: test the internal interface for debugging purpose
pthread_mutex_t mutex;
-static void* thread_fun(void* ignore)
+static void* thread_fun(void* val)
{
pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex);
+ fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
return NULL;
}
int main(int argc, char* argv[])
{
- fprintf(stderr, "User main is starting\n");
-
pthread_mutex_init(&mutex, NULL);
+ int id[2] = {0, 1};
pthread_t thread1;
pthread_t thread2;
- pthread_create(&thread1, NULL, thread_fun, NULL);
- fprintf(stderr, "here\n");
- pthread_create(&thread2, NULL, thread_fun, NULL);
- fprintf(stderr, "there\n");
+ 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);
- fprintf(stderr, "User main is done\n");
+ fprintf(stderr, "User's main is terminating.\n");
return 0;
}
--- /dev/null
+$ ./pthread-mutex-simple
+> [0.000000] [sthread/INFO] Starting the simulation.
+> The thread 0 is terminating.
+> All threads are started.
+> 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
/* Find the real __libc_start_main()... */
typeof(&__libc_start_main) orig = dlsym(RTLD_NEXT, "__libc_start_main");
- fprintf(stderr, "__libc_start_main\n");
/* ... and call it with our custom main function */
return orig(main_hook, argc, argv, init, fini, rtld_fini, stack_end);
}
std::ostringstream id;
id << std::this_thread::get_id();
- XBT_INFO("sthread main() is starting in thread %s", id.str().c_str());
+ XBT_DEBUG("sthread main() is starting in thread %s", id.str().c_str());
sg4::Engine e(&argc, argv);
auto* zone = sg4::create_full_zone("world");
sthread_enable();
sg4::ActorPtr main_actor = sg4::Actor::create("tid 0", lilibeth, raw_main, argc, argv, envp);
- XBT_INFO("sthread main() is launching the simulation");
+ XBT_INFO("Starting the simulation.");
sg4::Engine::get_instance()->run();
+ XBT_INFO("All threads exited. Terminating the simulation.");
return 0;
}
{
static int TID = 0;
TID++;
- XBT_INFO("Create thread %d", TID);
+ XBT_VERB("Create thread %d", TID);
int rank = 0;
#if HAVE_SMPI
if (SMPI_is_inited())