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

Graphics+Thread libraries problems #8394

Closed
vicuna opened this issue Dec 1, 2003 · 2 comments
Closed

Graphics+Thread libraries problems #8394

vicuna opened this issue Dec 1, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 1, 2003

Original bug ID: 1955
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Samuel Colin
Version: 3.07+2
OS: Linux
Submission from: alille-209-1-12-176.w81-249.abo.wanadoo.fr (81.249.41.176)

While mixing graphical and threaded programming, I happened to find some strange
bugs. First, here is a piece of code for you to test:
(**************)
open Graphics

let inputThread ()=
let gotEvent=Graphics.wait_next_event [Graphics.Button_down] in
print_endline ("mouse:" ^ (string_of_int gotEvent.mouse_x)
^ "," ^ (string_of_int gotEvent.mouse_y));
flush stdout

let _=
Graphics.open_graph "";
let t=Thread.create inputThread () in
let tid=Thread.id t in
Thread.join t;
Graphics.close_graph ()
(***************)

Compilations are made with:
ocamlc -o test -thread unix.cma threads.cma graphics.cma test.ml
and
ocamlopt -o test -thread unix.cmxa threads.cmxa graphics.cmxa test.ml

Bugs found:

-Bytecode :
scolin@hebus:/tmp/test$ ./test
mouse:31,269
scolin@hebus:
/tmp/test$ ./test
mouse:280,222
Erreur de segmentation

The second execution makes a segmentation fault (maybe does it come from the OS,
but I'm not sure).
And replacing "Thread.join t" with "ignore (Thread.wait_pid tid)" yields:
scolin@hebus:~/tmp/test$ ./test
Fatal error: exception Unix.Unix_error(5, "waitpid", "")

Given the documentation of the thread library, maybe the Graphics library should
be compiled with the "-thread" option?

The second bug comes from the Graphics library used in conjunction with the
Thread library (doesn't happen if the code of the inputThread function is put
directly in the "main" function):
-Bytecode : the event is detected, the mouse position is returned as expected
-Native code : the event is not detected, so the program doesn't end.
Adding Graphics.Poll in the list of events solves the problem, but maybe one
doesn't want to wait for the Poll event...

So, maybe all these bugs simply come from the fact that the Graphics library
isn't thread-safe.

Hope this helps...

@vicuna
Copy link
Author

vicuna commented Dec 2, 2003

Comment author: administrator

Hi,

So, maybe all these bugs simply come from the fact that the Graphics library
isn't thread-safe.

No, it isn't. Consider other libraries such as lablgtk2, if you want
to have graphics with threads.

--
Jun

@vicuna
Copy link
Author

vicuna commented May 30, 2004

Comment author: administrator

wait_next_event issue fixed 2004-05-30 by XL.
Thread.wait_pid(Thread.id t) is an obvious type confusion by the user, it's
normal that it doesn't work.

@vicuna vicuna closed this as completed May 30, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant