It runs pretty well and draws a nice 180Â° arc.
Now suppose I want to make it a thread. I turn it into a void function, remove the return(Pt_Continue), and change the callback function to call it using pthread_create. Then it still works, no problem.
Ok, now suppose I want to make it redraw every one second. I uncomment the commented lines, and then it will work once, but then crash.
My question is: why ? And how to avoid it ? (ok that’s 2 questions ^^ )[/code]
Put PtEnter() before your Photon function calls, and PtLeave() after them, Photon is not thread safe and those two functions block calls to Photon from other threads, making Photon calls safe to use in threads.
If u want to use PtEnter()/PtLeave() then u would have to implement them into all threads using Photon calls. Also, as u mentioned, calling PtSetResources() doesnt actually change display, it only schedule the update on next event-handle cycle. So, after calling PtSetResources() in second thread u have to let the first thread (the one which called PtMainLoop()) to update display.
Single thread with a Timer Callback is somewhat better solution …