Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault : Calling Julia from Multi Threaded C Program #20690

Closed
ravismula opened this issue Feb 20, 2017 · 1 comment
Closed

Segmentation fault : Calling Julia from Multi Threaded C Program #20690

ravismula opened this issue Feb 20, 2017 · 1 comment

Comments

@ravismula
Copy link

ravismula commented Feb 20, 2017

Getting Segmentation Fault in jl_load function.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffde0e73700 (LWP 12246)]
jl_enter_handler (eh=eh@entry=0x7ffde0e72300) at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:214
214	/home/centos/buildbot/slave/package_tarball64/build/src/builtins.c: No such file or directory.

Here is the part of C Code which calls Julia

#include "julia.h"
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int counter = 0;

void do_prediction(){
	printf("%d\n",counter);
	counter++;
	int i = 0;
		jl_value_t* mod = (jl_value_t*)jl_eval_string("MyModule");
		jl_function_t *func = jl_get_function((jl_module_t*)mod,"custom_compute");

		jl_value_t *ret = jl_call2(func, (jl_value_t*)1, (jl_value_t*)2);

		if (jl_exception_occurred())
			printf("%s \n", jl_typeof_str(jl_exception_occurred()));
		// jl_atexit_hook(0);
		cout << "Returned Value:" << jl_unbox_float64(ret) << endl;
		i++;
}

void* test2(){
	do_compute();
	sleep(10);
}

void* test1(void* p){
	test2();
	sleep(10);
}




int main(int argc, char *argv[]){
	jl_init(JULIA_INIT_DIR);
	jl_load("MyModule.jl");
	// test1(argv[1], argv[2]);
	int i;
	pthread_t p_test[10];

	for(i =0 ;i <10; i ++){
		/* create a second thread which executes inc_x(&x) */
		if(pthread_create(&p_test[i], NULL, test1, NULL)) {
			fprintf(stderr, "Error creating thread\n");
			return 1;

		}
	}

	for(i =0 ;i <10; i ++){
		/* wait for the second thread to finish */
		if(pthread_join(p_test[i], NULL)) {
			fprintf(stderr, "Error joining thread\n");
			return 2;
		}
	}
	return 1;
}

Without multi threading it works fine, but with multi threading it fails!

@ravismula ravismula changed the title Segmentation fault : jl_load Segmentation fault : Calling Julia from Multi Threaded C Program Feb 20, 2017
@yuyichao
Copy link
Contributor

Dup of #17573. It's not supported now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants