[fpc-pascal] FPC Graphics options?

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sun May 21 14:58:45 CEST 2017


On Thu, May 18, 2017 at 5:05 PM, Graeme Geldenhuys
<mailinglists at geldenhuys.co.uk> wrote:
> Use Java instead. ;-) Check. Oh wait, that's what I did for that project.

Well, Java also has its issues. I am studying Java and I am completely
shocked that you need to use "volatile" to avoid serious hard-to-debug
multithreading bugs.

It looks like you pretty much need to declare all vars that might be
accessed from different threads as volatile from what I understood,
because otherwise the java compiler might never write values to the
variable at all, instead write only to a local cache. Amazing!

In FPC this isn't needed since assignments always change real memory.
Thinking about it, maybe FPC needs the oposite kind of variable
modified, a "notvolatile" so that it could optimize more agressively
in case you are 100% sure this code will be run on a single thread...

This simple program never ends if you delete the volatile keyword (I
tested here in Windows):

import java.util.*;

class FelipeTestThread
{
    volatile boolean running = true;

    public void test()
{
        new Thread(new Runnable()
{
            public void run()
   {
                int counter = 0;
                while (running) {
                    counter++;
                }
                System.out.println("Thread 1 finished. Counted up to "
+ counter);
            }
        }).start();
        new Thread(new Runnable()
{
            public void run()
{
                // Sleep for a bit so that thread 1 has a chance to start
                try
{
                    Thread.sleep(100);
                } catch (InterruptedException ignored) { }
                System.out.println("Thread 2 finishing");
            running = false;
            }
        }).start();
  }
    public static void main(String[] args)
{
        new FelipeTestThread().test();
    }
}

Not to mention that 1 file per class is super annoying and it is
impossible to resize arrays and there are no unsigned integers.
Generics can't accept non-Object values. There is no way to pass
parameters by reference, accessing operating system APIs is a
nightmare which involves writing large JNI wrappers in C...etc.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list