# Workspace startup: error in Matlab codes

**URL:** <https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388>\
**Category:** Support\
**Created:** [June 19, 2017, 8:22pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388 "2017-06-19T20:22:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 19, 2017, 8:22pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/1 "2017-06-19T20:22:40Z")

</div>

Hi Chris,

I’m using MWorks 0.6 and testing with a workspace file (open /Applications/MWClient.app --args workspace.json).

When I start with a workspace file, I get very strange event timing in the stream that goes to Matlab.  
Some event codes have timestamps before the previous code in the stream (as measured in the event structure that gets passed to Matlab). Previously the sequence was always monotonically non-decreasing.

And the codes and values jump around a bit - the codes I see in the workspace-startup stream appear to be out of order.  
(The problems seem to occur near variable changes that call into the Labjack driver we use, but not always - not sure if this is related.)

Can you look into this? Let me know if you need more info.

Thanks,  
Mark

Example sequence from a normal startup (clicking icons in dock).  
Note some codes omitted for brevity.

Fields: event time (us); diff from prev code (us); code #; code name (from codec)

5407349751 0 197 sync  
5407349753 2 201 trialStart  
5407349755 2 191 juice  
5407349758 3 199 leverResult  
5407349760 2 189 laserTriggerFIO  
…  
5407349960 2 242 tDidLeverPressTasks  
5407370342 20382 236 debugUs  
5407380510 10168 237 tempMs  
5407380539 29 247 tSvStimNumber  
5407380541 2 244 tTempStimOdds  
5407380550 9 244 tTempStimOdds  
5407380557 7 244 tTempStimOdds

Example from a workspace startup:

* * *

963541879 0 197 sync  
963541882 3 201 trialStart  
963541883 1 191 juice  
963541886 3 199 leverResult  
963541888 2 189 laserTriggerFIO  
…  
963542063 2 242 tDidLeverPressTasks  
963539465 -2598 190 strobedDigitalWord  
963539937 472 190 strobedDigitalWord  
963540419 482 190 strobedDigitalWord  
963540948 529 190 strobedDigitalWord  
963541389 441 190 strobedDigitalWord  
963541879 490 197 sync  
963541882 3 201 trialStart  
963541883 1 191 juice

More examples.  
Standard:  
5408396033 2 269 tTotalRewardUl  
5408396035 2 198 pumpAmountUl  
5408396041 6 200 stimulusOn  
5408396043 2 190 strobedDigitalWord  
Workspace:  
963572505 3 269 tTotalRewardUl  
963572507 2 198 pumpAmountUl  
963572513 6 200 stimulusOn  
963571522 -991 237 tempMs

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 20, 2017, 11:44am UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/2 "2017-06-20T11:44:30Z")

</div>

One thing that might be unclear:

This behavior happens for every trial of a MWorks session, depending on how the Client is started. So starting with a workspace gives these negative-time-difference events on every trial, until MWorks is quit.

Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 20, 2017, 1:50pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/3 "2017-06-20T13:50:49Z")

</div>

Hi Mark,

> open /Applications/MWClient.app --args workspace.json

I’m surprised that works at all. Is the client already running when you issue this command, or are you trying to start the client and load the workspace in one shot? When I attempt the latter, the client crashes on me. You may be seeing memory corruption instead. I’ll try to figure out what’s going wrong.

In the meantime, if you want to launch the client and load a workspace from the command line or a shell script, I recommend doing it like this:

```
open /Applications/MWClient.app
sleep 3 # Give the client a moment to start up
open -a /Applications/MWClient.app workspace.json

```

Also, what happens when you open the workspace via “File-\>Open Workspace”? Do you still see the timestamp issue?

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 20, 2017, 7:23pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/4 "2017-06-20T19:23:17Z")

</div>

Hi Chris,

Yes, sounds it could be a memory corruption issue.

Your workaround works.

We definitely would like to start the client and load the workspace in  
one command, or at least immediately afterwards, so if you could look  
into making that possible, it would be great.

thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 10, 2017, 9:49pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/5 "2017-08-10T21:49:33Z")

</div>

Hi Chris,

I’m not sure where we left this - have you been able to see whether it’s possible to pass the workspace file to MWClient at startup in a way that doesn’t require a fixed delay? We’ve found we need to use 4s to avoid problems.

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 16, 2017, 1:57pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/6 "2017-08-16T13:57:20Z")

</div>

Hi Mark,

I fixed the bug that was causing MWClient to crash when I tried to launch the app and load a workspace in one shot. I don’t know if that will resolve the timestamp issue you’re seeing, but I hope it will.

The fix is in the current nightly build. Please try it when you have a chance.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 16, 2017, 2:27pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/7 "2017-08-16T14:27:39Z")

</div>

Hi Chris,

I tested this. The experiment seems to load fine in a first simple test.  
Thanks.

However two things I observed:

- If the experiment xml has an error, starting using workspace just leaves  
the experiment unloaded. I didn’t see the typical red error message.
- I’m seeing the below crash from time to time. I believe it happens on  
exit if I Cmd-Q the server before Cmd-Q on the client. I’ve seen it  
happen in thread 8,9, and 11 below:

* * *

Crashed Thread: 8

Exception Type: EXC\_CRASH (SIGABRT)  
Exception Codes: 0x0000000000000000, 0x0000000000000000  
Exception Note: EXC\_CORPSE\_NOTIFY

Application Specific Information:  
Performing @selector(terminate:) from sender NSMenuItem 0x6100000bba80  
terminating with uncaught exception of type  
mworks\_boost::exception\_detail::clone\_impl\<mworks\_boost::exception\_detail::error\_info\_injector\<mworks\_boost::lock\_error\>

> : boost: mutex lock failed in pthread\_mutex\_lock: Invalid argument  
> abort() called

Thread 0:: Dispatch queue: com.apple.main-thread  
0 libsystem\_kernel.dylib 0x00007fffad52719e poll + 10  
1 MWorksCore 0x000000010736056e  
zmq::signaler\_t::wait(int) + 58 (signaler.cpp:218)  
2 MWorksCore 0x000000010734f6e9  
zmq::mailbox\_t::recv(zmq::command\_t\*, int) + 169 (mailbox.cpp:81)  
3 MWorksCore 0x0000000107346f3b  
zmq::ctx\_t::terminate() + 485 (ctx.cpp:166)  
4 MWorksCore 0x0000000107373e51 zmq\_ctx\_term + 35  
(zmq.cpp:167)  
5 MWorksCore 0x000000010731cb92  
std::\_\_1::unique\_ptr\<void, mw::(anonymous  
namespace)::ContextDeleter\>::~unique\_ptr() + 30  
6 libsystem\_c.dylib 0x00007fffad48c178 \_\_cxa\_finalize\_ranges

- 332  
7 libsystem\_c.dylib 0x00007fffad48c4b2 exit + 55  
8 com.apple.AppKit 0x00007fff95978882 -[NSApplication  
terminate:] + 1851  
9 libsystem\_trace.dylib 0x00007fffad6293a7  
\_os\_activity\_initiate\_impl + 53

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 16, 2017, 3:08pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/8 "2017-08-16T15:08:23Z")

</div>

Hi Mark,

> If the experiment xml has an error, starting using workspace just leaves the experiment unloaded. I didn’t see the typical red error message.

I’m not able to reproduce this. When I load an experiment with an error, I _do_ see the error message in the server console. Can you send me an example experiment that demonstrates the problem?

> I’m seeing the below crash from time to time. I believe it happens on exit if I Cmd-Q the server before Cmd-Q on the client. I’ve seen it happen in thread 8,9, and 11 below:

OK, let me investigate.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 16, 2017, 3:33pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/9 "2017-08-16T15:33:16Z")

</div>

> I’m seeing the below crash from time to time. I believe it happens on exit if I Cmd-Q the server before Cmd-Q on the client.

The fix for this should be in tonight’s nightly build.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 17, 2017, 1:40pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/10 "2017-08-17T13:40:55Z")

</div>

> > I’m seeing the below crash from time to time. I believe it happens on exit if I Cmd-Q the server before Cmd-Q on the client.
> 
> The fix for this should be in tonight’s nightly build.

Sorry, I didn’t get it in yesterday. It will be in _tonight’s_ nightly build.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 9:54pm UTC](https://mworks.discourse.group/t/workspace-startup-error-in-matlab-codes/388/11 "2022-07-19T21:54:14Z")

</div>


