caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] signal-unsafety of %!
@ 2013-03-15 14:30 Matej Kosik
  2013-03-15 14:36 ` oliver
  0 siblings, 1 reply; 4+ messages in thread
From: Matej Kosik @ 2013-03-15 14:30 UTC (permalink / raw)
  To: caml-list; +Cc: Matej Kosik

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

Hi,

When I compile the attached program

  (with compilers available directly from Debian's repositories)

I can observe a (non-deterministic) deadlock.

When I remove

	%!

from the printf function inside the SIGALRM's handler, the deadlock never seem to occur.

Obviously, interference can be easily introduced in concurrent programs; I was just surprised that even something like

	%!

can cause it.

Isn't this something, that could be avoided in this case?

[-- Attachment #2: main.ml --]
[-- Type: text/plain, Size: 173 bytes --]

open Unix

;;

Sys.set_signal Sys.sigalrm
               (Sys.Signal_handle (fun _ -> Printf.printf "H%!"));
ignore (Unix.alarm 1);
while true do
  Printf.printf ".%!"
done

[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 94 bytes --]

main : % : %.ml
	ocamlfind c -linkpkg -package unix $< -o $@

clean :
	rm -f *.cmo *.cmi main

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] signal-unsafety of %!
  2013-03-15 14:30 [Caml-list] signal-unsafety of %! Matej Kosik
@ 2013-03-15 14:36 ` oliver
  2013-03-15 15:56   ` Matej Kosik
  0 siblings, 1 reply; 4+ messages in thread
From: oliver @ 2013-03-15 14:36 UTC (permalink / raw)
  To: caml-list

On Fri, Mar 15, 2013 at 02:30:29PM +0000, Matej Kosik wrote:
> Hi,
> 
> When I compile the attached program
> 
>   (with compilers available directly from Debian's repositories)
> 
> I can observe a (non-deterministic) deadlock.
> 
> When I remove
> 
> 	%!
> 
> from the printf function inside the SIGALRM's handler, the deadlock never seem to occur.
> 
> Obviously, interference can be easily introduced in concurrent programs; I was just surprised that even something like
[...]


Whats going on today?

Use Unix.sigprocmask.

Ciao,
   Oliver

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] signal-unsafety of %!
  2013-03-15 14:36 ` oliver
@ 2013-03-15 15:56   ` Matej Kosik
  2013-03-15 16:02     ` oliver
  0 siblings, 1 reply; 4+ messages in thread
From: Matej Kosik @ 2013-03-15 15:56 UTC (permalink / raw)
  To: caml-list

On 15/03/13 14:36, oliver wrote:
> On Fri, Mar 15, 2013 at 02:30:29PM +0000, Matej Kosik wrote:
>> Hi,
>>
>> When I compile the attached program
>>
>>   (with compilers available directly from Debian's repositories)
>>
>> I can observe a (non-deterministic) deadlock.
>>
>> When I remove
>>
>> 	%!
>>
>> from the printf function inside the SIGALRM's handler, the deadlock never seem to occur.
>>
>> Obviously, interference can be easily introduced in concurrent programs; I was just surprised that even something like
> [...]
> 
> 
> Whats going on today?
> 
> Use Unix.sigprocmask.
> 
> Ciao,
>    Oliver
> 

Right, printf simply isn't reentrant.

(what I was observing was a program that was busy-looping, but stuck. I guess because internal shared data might have been damaged.).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] signal-unsafety of %!
  2013-03-15 15:56   ` Matej Kosik
@ 2013-03-15 16:02     ` oliver
  0 siblings, 0 replies; 4+ messages in thread
From: oliver @ 2013-03-15 16:02 UTC (permalink / raw)
  To: Matej Kosik; +Cc: caml-list

On Fri, Mar 15, 2013 at 03:56:52PM +0000, Matej Kosik wrote:
> On 15/03/13 14:36, oliver wrote:
> > On Fri, Mar 15, 2013 at 02:30:29PM +0000, Matej Kosik wrote:
> >> Hi,
> >>
> >> When I compile the attached program
> >>
> >>   (with compilers available directly from Debian's repositories)
> >>
> >> I can observe a (non-deterministic) deadlock.
> >>
> >> When I remove
> >>
> >> 	%!
> >>
> >> from the printf function inside the SIGALRM's handler, the deadlock never seem to occur.
> >>
> >> Obviously, interference can be easily introduced in concurrent programs; I was just surprised that even something like
> > [...]
> > 
> > 
> > Whats going on today?
> > 
> > Use Unix.sigprocmask.
> > 
> > Ciao,
> >    Oliver
> > 
> 
> Right, printf simply isn't reentrant.
> 
> (what I was observing was a program that was busy-looping, but stuck. I guess because internal shared data might have been damaged.).

Ah, yes, you used it inside the signal handler.
Have overlooked it.

Ciao,
   Oliver

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-15 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15 14:30 [Caml-list] signal-unsafety of %! Matej Kosik
2013-03-15 14:36 ` oliver
2013-03-15 15:56   ` Matej Kosik
2013-03-15 16:02     ` oliver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).