Shop OBEX P1 Docs P2 Docs Learn Events
locking variables / pthreads... — Parallax Forums

locking variables / pthreads...

BloodyCactusBloodyCactus Posts: 6
edited 2013-05-08 11:13 in Propeller 1
so in LMM mode, I can use __lock and __unlock.. but what can I do when I compile against -mcog? since linking complains about a whole bunch of __CMPSWAPSI calls..
tried linking -lcog -lpthread etc but those missing calls dont go away.

so how do I go about locking and synching when using -mcog?

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2013-05-08 08:30
    so in LMM mode, I can use __lock and __unlock.. but what can I do when I compile against -mcog? since linking complains about a whole bunch of __CMPSWAPSI calls..
    tried linking -lcog -lpthread etc but those missing calls dont go away.

    so how do I go about locking and synching when using -mcog?
    Unfortunately there is too little memory in the COG to use most of the libraries. You pretty much need to write standalone code in COG mode. I think there may be a tiny version of printf that will work but not much else will fit.
  • BloodyCactusBloodyCactus Posts: 6
    edited 2013-05-08 08:40
    right, my cog code compiles at about 0x160 so, plenty of space for them to do locking/unlocking.. i just need to know how to do a spinlock in a cog since __lock/__unlock are not available. does the propeller have something like cmpxchg on x86?

    grepping libcog.a I see it has hits to __CMPSWAPSI, just linking my cog using __lock/__unlock gets 'undefined reference to..' so I see that __CMPSWAPSI is in the crt0.s asm files of lmm/cmm/xmm... but not crt0_cog.s

    hmm so popssibly I could take the locking code from crt0_lmm.s and stick it in crt0_cog.s.. ugh.
  • BloodyCactusBloodyCactus Posts: 6
    edited 2013-05-08 09:04
    so I believe I should be using something called locknew/lockset/lockclr instead of __lock / __unlock. tim eto go digging
  • David BetzDavid Betz Posts: 14,516
    edited 2013-05-08 09:12
    so I believe I should be using something called locknew/lockset/lockclr instead of __lock / __unlock. tim eto go digging
    Yes, those are the Propeller assembly instructions used for locking. There are built-in functions in PropGCC that directly expand into those instructions.
  • BloodyCactusBloodyCactus Posts: 6
    edited 2013-05-08 09:15
    cheers david (so when are we going to see bob on propeller??)
  • David BetzDavid Betz Posts: 14,516
    edited 2013-05-08 09:16
    cheers david (so when are we going to see bob on propeller??)
    I was thinking about porting Bob but there are already tons of languages ported to the Propeller. Someone even ported JavaScript recently.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-05-08 09:19
    David Betz wrote: »
    Yes, those are the Propeller assembly instructions used for locking. There are built-in functions in PropGCC that directly expand into those instructions.
    I should have mentioned this before. Look in propeller.h for macros to make use of the lock instructions.
Sign In or Register to comment.