Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [omr-dev] Modern package managers and build tools

Hi,

I have not personally looked into https://conan.io but in the past I have thought about breaking OMR into different GIT modules.  I have not found a clean way to break up the code base into modules that would not increase the complexity for downloading and building the source.  Conan may solve some of these issues so I will attempt to read through the documentation soon.

Most components can be included/not included based on the options used when running ./configure. If you want to only use the thread library you could run the following configure line which will only enable the thread library and the required util / tooling libraries:
./configure --enable-OMR_THREAD --disable-OMR_GC --disable-OMR_PORT OMRGLUE=my_glue

The best documentation at this point for the Thread Library APIs is to look at omr/include_core/thread_api.h.  I apologize that a lot of the functions are not properly documented at this time but it is something we are working on.  I will prioritize the thread library documentation and try to get it completed soon.

To help show the basics of the Thread library I wrote a simple program that initializes the thread library, attaches the main thread to the thread library, creates a monitor, creates a helper thread, uses the monitor to update a state variable between the two threads using monitor APIs and then cleans up and shuts down.  I wrote this code quickly so I do not make any claims about the quality :)

Here are the steps I used to run the test application on Linux.  I believe it would work on our platforms but I did not test it yet.
1. git clone https://github.com/eclipse/omr.git
2. cd omr
3. ./configure --enable-OMR_THREAD --disable-OMR_GC --disable-OMR_PORT OMRGLUE=my_glue
4. mkdir my_glue <---- since the thread library does not require any language glue and empty directory works
5. make <optional -j command line option>
6. cd <to the directory where I wrote the test>
7. g++ -I<path to omr>/include_core thread_test.cpp -o thread_test <path to omr>/lib/libomrstatic.a -lpthread

If you have any questions please let me know and I will gladly help.  If there is particular threading functionality that you are looking for the omr/fvtest/threadtest and omr/fvtest/threadextendedtest contain a lot of examples.

Cheers,
Charlie Gracie

On Sun, Dec 11, 2016 at 4:46 PM, Nick Pavlov <gurinderu@xxxxxxxxx> wrote:
Hi, team.

What do you think about using https://conan.io/ in your project and split current code on few modules? I think it is a good idea because now I interested in usage only threads library and I don't want to build all project. I have many compilation problems in other unnecessary  modules. 

Also, could you share documentation how to use your threads library?
omrthread.c isn't simple for understanding without documentation))

Thanks.

_______________________________________________
omr-dev mailing list
omr-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/omr-dev


#include "stdio.h"

#include "thread_api.h"


struct ThreadTestData {
	omrthread_monitor_t helper_monitor;
	uintptr_t state;
};

static int thread_entry_point(void *arg)
{
	ThreadTestData *test_data = (ThreadTestData *)arg;

	printf("Thread[%p] is now running\n", omrthread_self());

	omrthread_monitor_enter(test_data->helper_monitor);
	test_data->state = 1;
	printf("Thread[%p] successfully changed state to 1\n", omrthread_self());
	omrthread_monitor_notify(test_data->helper_monitor);
	omrthread_exit(test_data->helper_monitor);

	return 0;
}

int main(){

	omrthread_t omr_self = NULL;

	if (0 != omrthread_init_library()) {
		printf("Failed to initialize OMR thread library\n");
		return -1;
	}

	printf("OMR thread library initialization complete\n");

	if (0 != omrthread_attach_ex(&omr_self, J9THREAD_ATTR_DEFAULT)) {
		printf("Failed to attach main thread\n");
		return -2;	
	}

	printf("Successfully attached main thread to OMR thread library %p\n", omrthread_self());

	ThreadTestData test_data;
	test_data.helper_monitor = NULL;
	test_data.state = 0;

	if (0 != omrthread_monitor_init_with_name(&test_data.helper_monitor, 0, "helper monitor")) {
		printf("Thread[%p] failed to create helper monitor\n", omrthread_self());
		return -3;
	}

	printf("Thread[%p] successfully created the helper monitor %p\n", omrthread_self(), test_data.helper_monitor);

	omrthread_t wait_thread = NULL;

	if (0 != omrthread_create_ex(&wait_thread, J9THREAD_ATTR_DEFAULT, 0, thread_entry_point, &test_data)) {
		printf("Thread[%p] failed to create helper thread\n", omrthread_self());
		return -4;
	}

	printf("Thread[%p] sucessfully created helper thread %p\n", omrthread_self(), wait_thread);

	omrthread_monitor_enter(test_data.helper_monitor);
	while (0 == test_data.state) {
		omrthread_monitor_wait(test_data.helper_monitor);
	}
	omrthread_monitor_exit(test_data.helper_monitor);

	printf("Thread[%p] successfully waited for helper thread to update the status\n", omrthread_self());

	if (0 != omrthread_monitor_destroy(test_data.helper_monitor)) {
		printf("Thread[%p] failed to destroy the helper monitor\n", omrthread_self());
		return 5;
	}

	omrthread_shutdown_library();

	printf("Shutdown the OMR Thread library\n");
	return 0;
}

Back to the top