Skip to content

Multi-threading example is not multi-threading #57

@lucwens

Description

@lucwens

On Windows 10 and with julia 1.9.3-64 bit, the multi-threading examples from the documentation do not seem to multi-thread. The supposedly multi-threading tasks are executed in the main thread upon calling join(), they do not start before the sleep_for statement in main.

#include
#include <julia.h>
#include <jluna.hpp>
JULIA_DEFINE_FAST_TLS // only define this once, in an executable (not in a shared library) if you want fast code.

using namespace std;
using namespace jluna;

int main(int argc, char* argv[])
{
jluna::initialize(8);
std::vector<Task> tasks;
{
// declare lambda
std::function<void()> print_numbers = -> void
{
for (size_t i = 0; i < 10000; ++i)
if (i%100 == 0)
std::cout << i << std::endl;
};

	// add task to storage
	tasks.push_back(ThreadPool::create(print_numbers));

	// wait for 1ms
	std::this_thread::sleep_for(1ms);
}

for (auto& Task : tasks)
	Task.schedule();

// wait for another 10ms
std::this_thread::sleep_for(10000ms);
std::cout << "Main waited 10 sec" << std::endl;

for (auto& Task : tasks)
	Task.join();

return 0;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedthe team is aware of this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions